Jump to content

onclick problem


ameliabob

Recommended Posts

I am generating a table where the element below (when clicked) calls the SetTF function. The label passed alert functions with the correct label. But the var idIndex doesn't seem to work. At least the diagnostic says "idIndex is undefined."

 

Is there something about not being able to pass a variable into a routine or that is must be hard coded?

 

 

 

Failing Routine: function SetTF(id){ alert('label passed is '+id); var idIndex = id.selectedIndex; var valu=id.options[idIndex].value; SendOffRequest("setprofilefield&which="+id+"&value="+valu); }  Element in table that calls the above routine: <tr><td>Follow Gaps</td><td align='right'><select size ='2' id='followGaps' onclick=SetTF('followGaps')><option value='True'>True</option><option selected value='False'>False</option></select></td></tr>
Link to comment
Share on other sites

the "id" which you've passed is just a string. its not a DOM element object and as such, it doesn't have the properties selectedIndex or options.

 

You can also change the onclick event to onclick="SetTF(this)" as another option. Since the element you want to work on is the very same element thats calling the event, you can use "this". The 1st alert won't show what you've expected but the rest of the function should work flawlessly.

 

If you're using a diagnostic, start playing with the console object for debugging. console.dir(id) should let you see everything that the variable id had in it. it would've quickly helped you find out that id was just a string.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...