Jason Young

Jason Young

  • NA
  • 2
  • 0

Get element ID from a clicked checkbox into numeric variable

Apr 14 2009 11:24 AM
I have a form with 200 plus checkboxes. When the checkbox is checked onClick passes (this) to a Javascript function. I need to get the element array ID of the just checked checkbox into a numeric variable. The following routine never finds a match. The value returned in thisCheckID is blank when I send it to a text field. function getcheckboxid(formobj) { var checkboxname=formobj.name; var checks = document.getElementsByTagName("INPUT"); var len = checks.length; var thisCheck, thisCheckID; for (var i = 0; i < len; i++) { if (checks[i].name == checkboxname) { thisCheckID = checks[i].id; } document.form1.text1.value=thisCheckID; }