Solved

Pass value from a function into an onclick

Posted on 2006-07-13
8
213 Views
Last Modified: 2008-02-26
Here's what I have.
 
1st anchor tag that launches initiates the transfer: <a href="" onclick"functionOne('uniqueInfo');">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('uniqueId').onclick.value;
  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.
0
Comment
Question by:crazycharlie
  • 3
  • 3
  • 2
8 Comments
 
LVL 30

Accepted Solution

by:
third earned 250 total points
ID: 17106201
pass it through a global variable. like,

var myVar = '';

functionOne(info) {
  myVar = info;
}
 
functionTwo() {
    alert(myVar);
}
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17106263
and make sure you do

 
<a href="#" onclick="functionOne('uniqueInfo'); return false">Click Me</a>
0
 

Author Comment

by:crazycharlie
ID: 17106272
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
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17106455
I would STILL use

<a href="#" onclick="functionOne('uniqueInfo'); return false">Click Me</a>

since that does not give a 404 if you disable javascript
0
 

Author Comment

by:crazycharlie
ID: 17106465
Thanks, mplungjan.  I didn't think about the non-javascript aspect.
0
 
LVL 30

Expert Comment

by:third
ID: 17106467
i agree with michel.

onclick"

should be

onclick="
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 17106819
thanks, Third...
0
 

Author Comment

by:crazycharlie
ID: 17109371
Thanks, guys.  I had the '=' in there... was just a typo when I entered the original code.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question