PDA

View Full Version : A JScript action within a form



multichild
01-04-2007, 09:36 AM
I have a simple HTML form, that is asking the user for details on events.
When a certain event is selected in a checkbox, the user then has to select some otherinformation from a drop down box.

I have this piece of code, and it doesnt seem to be working:

if (theform.weddings_cbox.value=="Information please"&&theform.eventMonth.options[0].selected){
alert("Please ensure that you select your preferred month and year for your wedding day.");
theform.eventMonth.focus();
return false;
}

What Im asking it to do, is check if the checkbox has been selected but if the user hasnt followed the command to selct the month or year then that alert comes up.

Whats happening, is that alert pops up regardless of whether the checkbox has been selected or not.

Can anybody take a look for me.

Lee

DimX
01-04-2007, 11:37 AM
Try that:


if (theform.weddings_cbox.checked && theform.eventMonth.selectedIndex == 0) {
alert("Please ensure that you select your preferred month and year for your wedding day.");
theform.eventMonth.focus();
return false;
}

multichild
01-04-2007, 11:45 AM
Thank you very much, that did the trick

cheers

Lee