javascript getting form component
i have an input <input type = "checkbox" name = "checkboxDel[]" ....>
how can i use javascript form. to get the checked value? or get the component name itself. as when i do a post the query string of this component is ...&checkboxDel%5B%5D=25&...
anyone has better idea of how to go about?
thanks...
Re: javascript getting form component
Use getElementById().
Code:
<input type="checkbox" name="checkboxDel[]" id="checkbox1" ....>
<script type="text/javascript">
var theCheckbox = document.getElementById('checkbox1');
if(theCheckbox.checked){alert('Checked!');}
</script>
Re: javascript getting form component
oh use by id.. hmm i found some code which uses form['checkboxDel[]'][i].value .. does it works the same?
Re: javascript getting form component
Well, you are close, but not exactly. If you only have one form on the page you could also use...
Code:
document.forms[0].checkboxDel[INDEX].checked
Remember that the index will be an integer because you have created an array of checkboxes.
EDIT: document.form[] returns an array of all forms on the page, so if you have more than one, you will have to adjust the index accordingly. Or use the form name as the index as a associative array.