Click to See Complete Forum and Search --> : onchange function dropdown list/menu


iunology
11-04-2003, 06:33 PM
Please Help

I have a drop down list/menu. I need to place an onchange function pointing to a url“ON THE SELECTED OPTION VALUE” .

Example
<option value = “Monday”>Monday</option>
<option value = “Tuesday”>Tuesday</option>

When the user select “Monday” (onchange) a popup will inform them that they are going to “url” on close of the popup they will automatically go to a specified url.

The catch....I need to place the redirect on some but not all of the options. (i.e. if they select Monday, they will go to a url, however if they select Tuesday, they will stay and continue filling in the form.

Specifically, some options will need to user to fillout another form, so when they select that option, I need them to go to another url. Other wise they will pass through.

Please Help.

gil davis
11-04-2003, 09:31 PM
The easiest way to do that is to add something to the value of the select which will tell you whether to change pages or not. Or you can get more sophisticated and use an array to hold the option to change pages.

iunology
11-04-2003, 09:53 PM
Are you able to provide any examples, or an alternative.

iunology
11-04-2003, 10:34 PM
I found it. Thanks for your reply. However when I employ this, my other onchange function doesn't work.

Any help on correctly writing two onchange commands on the same select option. This is what I courrently have.

<select name="variablename" onChange="doSel(this);otherfunction(this)">

-------This is the good code-------

<form name="jsMenu">
<select name="jsSelList" size="1" onchange="doSel(this)">
<option selected value>Select a page</option>
<option value="location.href='http://www.domain.com'">name</option>
<option value="something">name2</option>
</form>

-----
<SCRIPT LANGUAGE="JavaScript">

function doSel(obj)
{
for (i = 1; i < obj.length; i++)
if (obj[i].selected == true)
eval(obj[i].value);
}

</SCRIPT>

gil davis
11-04-2003, 10:54 PM
From what you have posted, it looks like you are trying to change the page (location.href=...). You really cannot expect the other function to work after the page has started to change.

You need to sit down and write out the sequence of events and plan them out logically, then implement your plan in script.

Also, your doSel() could be done simpler. The way you have it only has to be done like that if the select box is declared "multiple".

eval(obj.options[obj.selectedIndex].value);

which would also be a cross-browser solution.