|
Subject:
|
get the checked value from a checkbox array
|
|
Posted By:
|
teklline123
|
Post Date:
|
9/15/2006 11:41:49 PM
|
Here is my sample code:
Alert ("checked = " + document.gemOptions.elements['gem[]'].checked);
where gemOptions is the formName and gem[] is the checkbox name array. Incidently this alert box displays 'checked = undefined' My problem is that I cannot use this in an if statement because I cannot get the correct returned value. Is the element checked? How do I know?
Please help me.
eg.
<form name="gemOptions" method="post" action="" onsubmit=""> <table> <tr><td> Diamond <input type="checkbox" name="gem[]" value="Diamond"> </td> <td> Pearl <input type="checkbox" name="gem[]" value="Pearl"> </td> <td> Emerald <input type="checkbox" name="gem[]" value="Emerald"> </td> <td> Ruby <input type="checkbox" name="gem[]" value="Ruby"> </td> <td> Saphire <input type="checkbox" name="gem[]" value="Saphire"> </td> </tr> <tr> <td> <input type="reset" value="Finished" onclick="javascript: ShowMenu(document.getElementsByName('gem[]'),'gemForm',document.gemOptions.elements['gem[]'])"> </td> </tr>
</table>
|
|
Reply By:
|
joefawcett
|
Reply Date:
|
9/16/2006 11:02:27 AM
|
As far as I know [] are not legal name characters but your main problem is that there's no shortcut for this task. You need to loop through the checkboxes and test each one. What do you want to know, which are checked or are any checked? Are you sure you want checkboxes not a radio group where only one can be picked?
--
Joe (Microsoft MVP - XML)
|