Okay kids. Here's another strange one. Very simple form. The array is
dynamically generated from PHP as per the suggested method:
http://us2.php.net/manual/en/faq.html.php#faq.html.arrays
However, when there is only a single element, the myMultiSelect.length is
undefined in javascript.
If there are two or more elements, then the length works as expected...
---------------------- snip ----------------------
<SCRIPT>
function checkAudits()
{
var theForm = document.AddSchedule;
var myMultiSelect = theForm['RunVuln[]'];
// this doesn't work either.
//var a = document.forms[0].elements['RunVuln[]'].length;
//alert("a: " + a);
selectedAudits = 0;
for(i = 0; i < myMultiSelect.length; i++)
if (myMultiSelect[i].checked) selectedAudits++;
alert("selectedAudits: "+selectedAudits+" myMultiSelect.length:
"+myMultiSelect.length);
if (selectedAudits < 1)
{
alert("You must select at least one.");
return false;
}
return true;
}
</SCRIPT>
<FORM ACTION="/poop.php" METHOD=POST NAME="AddSchedule">
<input type=checkbox name="RunVuln[]" value="foo"> foo <BR>
<!-- uncomment this line and it works. with it commented, the length
is undefined. WTF?!
<input type=checkbox name="RunVuln[]" value="bar"> bar <BR>
-->
<INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Update Selections"
onClick='return checkAudits();'>
</FORM>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php