?
Solved

Pass value from a function into an onclick

Posted on 2006-07-13
8
Medium Priority
?
216 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
8 Comments
 
LVL 30

Accepted Solution

by:
third earned 1000 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
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…
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…
Suggested Courses

752 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