[SOLVED]Referencing form arrays using JavaScript
Posted: Mon Aug 04, 2008 10:48 am
Right. Say I've got a form like this:
And confirmDeletions() looks like this:
Currently it is telling me that length is 1, the value of the only element is "on" and then asking me to confirm.
I know that I am grabbing the array of checkboxes incorrectly (because the length should be 2), can someone point me in the right direction? Google brings up nothing except for how to handle the document.forms array and the elements array.
Code: Select all
<form onSubmit="return confirmDeletions();">
<input type="checkbox" name="del[]" id="del[]" />
<input type="checkbox" name="del[]" id="del[]" />
<input type="submit" />
</form>
Code: Select all
function confirmDeletions() {
var del = Array(document.getElementById('del[]'));
var conf = false;
alert('length: ' + del.length);
for(var x=0; x < del.length; x++)
{
if(del[x].value != null)
{
alert(del[x].value);
conf = true;
}
}
if(conf == true)
return confirm('Are you sure you want to delete the selected waiters?');
return true;
}
I know that I am grabbing the array of checkboxes incorrectly (because the length should be 2), can someone point me in the right direction? Google brings up nothing except for how to handle the document.forms array and the elements array.