Forum Moderators: open

Message Too Old, No Replies

Script to disallow first choice in dropdown

How to do it for two drop downs on same form?

         

kriskd

3:23 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



I have the following javascript function set up for one of the dropdowns on my form:

function confirm_Neighborhood()
{

// Check to see if the dropdown value is is the first choice
if (dropdown.Neighborhood.selectedIndex == 0)
{

// If the first choice is selected display an alert box
// stating the first choice is not a valid selection
alert("Please select your neighborhood.");

// Focus on the dropdown menu after OK is clicked from the alert box
dropdown.Neighborhood.focus();
return (false);
}
// A choice other than the first was selected
// cotinue processing the form request
return (true);
}

And here is the HTML that calls it:

<form name="dropdown" method="post" action="http://www.mydomain.com/cgi-bin/bizmail.cgi" onsubmit="return confirm_Neighborhood()">

My question (and hopefully a simple one), how do I duplicate this for other drop down boxes I want to add to the form? If the answer is to duplicate the function with the different variable names, then how do I call it? Add another "onsubmit"?

I'm new at this so, be easy on me! ;)

kriskd

3:58 pm on Mar 6, 2005 (gmt 0)

10+ Year Member



Never mind... with a little logical thinking I got it.

I just placed the "if then" portion of the 2nd function with the different variable names after return(false) of the first statement.

Works like a charm!