1

I am attempting to take 2 variables, perform math on them and then output them as a new 3rd variable. Here's the basic logic I attempting to do:

var A1 = [+ditto_iteration+]
var B1 = [+gallery_currentPage+]
var C1 = (B1-1)*3+A1+1

Then I need to take the value of the variable C and output in some HTML like so:

<a href="variable C1 here">link</a>

So to clarify, I've got some programming that will output the value of [+ditto_iteration+] on page load. Same with [+gallery_currentPage+]. I just need to be able to take the variable values of A1 and B1, perform the math as shown above and then replace a variable in the URL (in this case C1) with the resulting value of the math operation.

0

4 Answers 4

4
<script>
var A1 = parseInt([+ditto_iteration+]);
var B1 = parseInt([+gallery_currentPage+]);
var C1 = (B1-1)*3+A1+1;

$('#link').attr('href', C1);

</script>


<a id='link' href="variable C1 here">link</a>
Sign up to request clarification or add additional context in comments.

Comments

1
var A1 = 10,
    B1 = 30,
    C1 = (B1 - 1) * 3 + A1 + 1;

$('a').attr('href', C1).text('C1 value is ' + C1);

Live here http://jsfiddle.net/q3EL3

Comments

1

Try this:

<a id="replaceMe" href="variable C1 here">link</a>

and your jQuery:

$('#replaceMe').attr('href',C1);

Fiddle: http://jsfiddle.net/whQ5v/

After reading the title I was tempted to post this naked link: https://i.sstatic.net/ssRUr.gif

Comments

0

if you give the element an id like so:

<a id="c1val" href="variable C1 here">link</a>

you can do it much easier.

With the id attribute

$("a#c1val").attr("href",C1 + ''); //Adding empty string makes C1 a string

Without the id attribute (only works once)

$('a[href="variable C1 here"]').attr("href",C1 + ''); //Adding empty string makes C1 a string

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.