Click to See Complete Forum and Search --> : What's wrong with this code? Checking a choice in a Dropdown.


kelemvor
03-12-2003, 11:02 AM
When I put this code in my page (even if it's not ever called) I get some strange Object Expected error message.

Can anyone see anything I'm missing? The field called Delivery is a dropdown box with 3 choices. Mail is one of the choices. How do I reference what is chosen since it seems Value isn't it.



if document.FrontPage_Form1.Delivery.value == "Mail"
{
mail = 1;
}

pyro
03-12-2003, 11:05 AM
You forgot your ( ) around your if command...

It should be:

if (document.FrontPage_Form1.Delivery.value == "Mail")
{
mail = 1;
}

kelemvor
03-12-2003, 11:07 AM
Ah christ. Figured it was something dumb but not that dumb.
*blush*

Fixing that made the error go away but it's not doing the part in side the IF Statement. Is the syntax of that also wrong? I need to check which item is selected on a Dropdown Box.

THanks. :)

pyro
03-12-2003, 11:16 AM
try this syntax out:

if (document.FrontPage_Form1.Delivery.options[document.FrontPage_Form1.Delivery.options.selectedIndex].value == "Mail")

;)

kelemvor
03-12-2003, 11:21 AM
Here's the field I'm trying to check in case something is set up wrong there.


<select size="1" name="Delivery">
<option selected>--Choose One--</option>
<option>Mail</option>
<option>Pick Up</option>
</select>

pyro
03-12-2003, 11:24 AM
Should be:

<select size="1" name="Delivery">
<option selected>--Choose One--</option>
<option value="Mail">Mail</option>
<option value="PickUp">Pick Up</option>
</select>

Notice how I changed the value of Pick Up to PickUp. I wouldn't use spaces as the actual value...

kelemvor
03-12-2003, 11:30 AM
I just noticed that as well. I guess I can add the values or change the thing to look at the TEXT instead of the VALUE.

Probably safer to set the value so I'll do it that way