Click to See Complete Forum and Search --> : Selection alerts - please help!
Tricky123
12-20-2002, 05:04 AM
Is it possible to put an alert for each option in a selection.
So, if i have the following selection item:
<select name= "SelectionOne">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
can I return an different alert for each option?
TIA
Rick Bull
12-20-2002, 05:13 AM
Somehthing like this may be what you want:
<script type="text/javascript"><!--
function doAlert(optionValue) {
switch(optionValue) {
case "1":
alert('Message 1');
break;
case "2":
alert('Message 2');
break;
case "3":
alert('Message 3');
break;
}
}
//--></script>
<select name= "SelectionOne" onchange="doAlert(this.options[this.selectedIndex].value);">
<option value="1" >1</option>
<option value="2" >2</option>
<option value="3" >3</option>
Tricky123
12-20-2002, 05:37 AM
Hi,
Thanks for the help! However, I need to be able to pass the alert messages from parameters in the doAlert() call. Further more, it would not be possible for me to use this sort of function:
doAlert('message1','message2',',message3')
(There is a complicted reason for this due to the way my scripts are written from another program)
I had thought something like this would be possible :
<script language="JavaScript">
function valSel(Name,Msg)
{
if (Name.options[0].selected)
{alert(Msg);}
//repeat for each line or perhaps do a loop [i]
}
</script>
<select name= "SelectionOne">
<option value="1" onSelect="return valSel(document.MyForm.SelectionOne,'Warning ONE')" >1</option>
<option value="2" onSelect="return valSel(document.MyForm.SelectionOne,'Warning TWO')">2</option>
<option value="3" onSelect="return valSel(document.MyForm.SelectionOne,'Warning THREE')">3</option>
</select>
What do you think?