Solved

Pass value from a function into an onclick

Posted on 2006-07-13
8
210 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
Comment Utility
pass it through a global variable. like,

var myVar = '';

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

Expert Comment

by:Michel Plungjan
Comment Utility
and make sure you do

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

Author Comment

by:crazycharlie
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

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

Expert Comment

by:third
Comment Utility
i agree with michel.

onclick"

should be

onclick="
0
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
thanks, Third...
0
 

Author Comment

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

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

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.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now