Solved

Pass value from a function into an onclick

Posted on 2006-07-13
8
214 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 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
disable open new tab with right mouse click in <a> tag 3 36
Set css in function 11 48
How to send a javascript array via AJAX (jquery)? 3 36
Slow Down an Animation 3 25
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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…

740 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