I need to check a form (consisting mostly of select elements) and ensure that none of the values are empty/null.
Unfortunately I don't know how many select elements there will be so I need to be able to loop through as many items as there could possibly be.
Form example;-
Expand|Select|Wrap|Line Numbers
- <form id='FormID' action='action.php'>
- <select name='select1'>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- <select name=select2'>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- <select name='select3'>
- <option>Option 1</option>
- <option>Option 2</option>
- <option>Option 3</option>
- </select>
- </form>
Expand|Select|Wrap|Line Numbers
- var elem = document.getElementById('FormID').elements;
- for(var i = 0; i < elem.length; i++)
- {
- if (elem[i].value == "")
- {
- alert("One of the fields was blank");
- return;
- }
- }
Can anyone please help me adjust the code above to properly check the fields in IE ?
Many thanks
Phil