Advertisement

06.02.2006 at 11:12AM PDT, ID: 21872844
[x]
Attachment Details

onclick

Asked by mattjp88 in JavaScript

Tags: onclick, javascript

I am writing a script that need to change the onclick attribute of DIVs.  I can't simply use:

var myvar='aa';
my_div.onclick="myfunction(myvar)";

not sure why, but it doesn't work.  I am going to be using a loop and changing a bunch of onclick attributes at once, so the "myvar" variable, will be the incriment variable.  I tried:

my_div.onclick=function(){myfunction(myvar);};

but again, it did not work.  myvar was not passed in correctly because it uses the max value of the loop, because when that 'function' gets called, it goes and finds myvar, instead of replacing myvar when I create the function.  

So the question.  I need to know how to change the onclick attribute of a DIV via javascript and have the function the onclick is changed to accept a parameter that can not be hard coded.

Any help would be great.

Thanks,
MattStart Free Trial
Related Solutions: onclick doesn't work in firefox
[+][-]06.02.2006 at 11:19AM PDT, ID: 16818956

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: JavaScript
Tags: onclick, javascript
Sign Up Now!
Solution Provided By: archrajan
Participating Experts: 4
Solution Grade: A
 
 
[+][-]06.02.2006 at 11:34AM PDT, ID: 16819052

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.02.2006 at 12:13PM PDT, ID: 16819396

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.02.2006 at 02:46PM PDT, ID: 16820579

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.03.2006 at 11:43PM PDT, ID: 16826165

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2006 at 09:11AM PDT, ID: 16827541

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2006 at 02:09PM PDT, ID: 16828742

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.05.2006 at 07:12AM PDT, ID: 16833129

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.05.2006 at 08:56AM PDT, ID: 16834178

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.15.2006 at 07:12AM PDT, ID: 16911599

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]06.15.2006 at 07:15AM PDT, ID: 16911627

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32