I've got 2 'select' tags in my form allowing a user to choose tour_1 or tour_2 BUT NOT both. Tour_1 and Tour_2 can't be 'options' in the same select tag as they have different pick-up points which are listed in the seperate 'select' tags. I dont want the user to be able to send the form unless one or the other of the 'select' tags has been chosen BUT NOT both.
So I can t get one working:
var pp = document.forms.purchaseTickets.tour_1.value;
var pa = document.forms.purchaseTickets.tour_2.value;
if (pp == null || pp == "")
{
alert("Please choose a pick-up point!");
return false;
}
This only checks that tour_1 'select' tag is not empty BUT if I also select something from tour_2 'select' tag it also will allow that to be sent as well, bum! bum!
I can't check for both 'select' tags being empty as that will only prompt the user to choose a selection from both,
So what I need is to allow the form to be sent if the user has chosen an option from one or the other of the 'select' tags but not if they have chosen and option from both by mistake.
Cheers
Os.
SELECT does not give a value, directly. You can use selectedIndex, or the value of the option that is selected (again, selectedIndex).
Assuming that the form name is purchaseTickets:
var pp = document.forms["purchaseTickets"].tour_1;
var pa = document.forms["purchaseTickets"].tour_2;
if(pp.selectedIndex == 0 && pa.selectedIndex == 0) { // Neither option selected
do stuff
}
if(pp.selectedIndex != 0 && pa.selectedIndex !=0) { // Both options selected
so something else
}
^_^
North America
Europe, Middle East and Africa
Asia Pacific