Forum Moderators: open
my eyes are red from googling, trying to find the answer out there, and it occured to me that someone in here would know what to do, just off the top of their head. so can anyone point me the right way?
thanks!
<select name="select" onchange="if(this.options[this.selectedIndex].value=='OptionC') { document.location.href='http://www.mysite/pageC.html'; }">
<option value="optionA">optionA</option>
<option value="optionB">optionB</option>
<option value="optionC">optionC</option>
</select>
<select name="select" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value="http://www.mysite/pageA.html">optionA</option>
<option value="http://www.mysite/pageB.html">optionB</option>
<option value="http://www.mysite/pageC.html">optionC</option>
</select>
thanks alot for your help!
that does kind of answer my question, but now creates another problem... (sorry for poorly worded question in the first place!)
now, the user is sent to another url no matter what selection is made. actually, what i wanted to do was to allow the user to stay on the page (and continue filling in the form) if they selected, say, optionA or optionB; but for the user to be sent to pages C, D or E if optionC, optionD or optionE were selected. kind of a mixed outcome.
is there a way to tweak your code above to achieve that?
<select name="select" id="select">
<option value="optionA">optionA</option>
<option value="optionB">optionB</option>
<option value="optionC">optionC</option>
</select>
Next, add your behavior in a script file, and include it in the head of your document. You'll want to attach the behavior handler once the document has finished loading.
function selectCallback(s)
{
// This function gets called when selection changes
if( s.selectedIndex == -1 ) return;
var v = s.options[s.selectedIndex].value;
switch(v) {
case 'optionA':
// Go to page A
document.location.href='http://www.example.com/pageA.html';
break;
case 'optionB':
document.location.href='http://www.example.com/pageB.html';
break;
default:
// Do nothing for other selections
break;
}
}
function attachBehaviors()
{
// Attach event handler to your select object
var s = document.getElementById("select");
if( s )
{
s.onchange = function(){selectCallback(s);};
}
}
window.onload = attachBehaviors;
There are cleaner ways to attach event handlers, using the Yahoo UI Library [developer.yahoo.com]'s Event Utility [developer.yahoo.com] for example. However, this should work.
[edited by: Fotiman at 5:42 pm (utc) on Nov. 27, 2006]