crazycharlie
asked on
Pass value from a function into an onclick
Here's what I have.
1st anchor tag that launches initiates the transfer: <a href="" onclick"functionOne('uniqu eInfo');"> Click Me</a>
2nd anchor tag that should receive the info: <a href="" id="uniqueId" name="uniqueId" onclick="">Click Me Next</a>
The JS I have basically does this:
functionOne(info) {
myVariable = document.getElementById('u niqueId'). onclick.va lue;
myVariable = 'functionTwo(\'' + info + '\');';
}
functionTwo(moreInfo) {
...
}
So, what it's supposed to do is take the data from the first anchor and pass it into functionOne. functionOne should set the onclick value of anchor 2 to be functionTwo('uniqueInfo');
I've set an alert after the second line in functionOne (ie, alert(myVariable); ) and it alerts the correct info. But that info ISN'T being inserted into the onclick attribute of anchor 2 at all.
1st anchor tag that launches initiates the transfer: <a href="" onclick"functionOne('uniqu
2nd anchor tag that should receive the info: <a href="" id="uniqueId" name="uniqueId" onclick="">Click Me Next</a>
The JS I have basically does this:
functionOne(info) {
myVariable = document.getElementById('u
myVariable = 'functionTwo(\'' + info + '\');';
}
functionTwo(moreInfo) {
...
}
So, what it's supposed to do is take the data from the first anchor and pass it into functionOne. functionOne should set the onclick value of anchor 2 to be functionTwo('uniqueInfo');
I've set an alert after the second line in functionOne (ie, alert(myVariable); ) and it alerts the correct info. But that info ISN'T being inserted into the onclick attribute of anchor 2 at all.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, third. I actually figured it out and was coming back here to disable my question. No biggie... :D
mplungjan, I actually used href="javascript:void(0);"
Cr@zyCh@rlie
mplungjan, I actually used href="javascript:void(0);"
Cr@zyCh@rlie
I would STILL use
<a href="#" onclick="functionOne('uniq ueInfo'); return false">Click Me</a>
since that does not give a 404 if you disable javascript
<a href="#" onclick="functionOne('uniq
since that does not give a 404 if you disable javascript
ASKER
Thanks, mplungjan. I didn't think about the non-javascript aspect.
i agree with michel.
onclick"
should be
onclick="
onclick"
should be
onclick="
thanks, Third...
ASKER
Thanks, guys. I had the '=' in there... was just a typo when I entered the original code.
<a href="#" onclick="functionOne('uniq