...

View Full Version : Popup Message When Specific Option Selected



bjblackmore
12-08-2008, 01:30 PM
Hi,

I have a dropdown box with a few options that can be selected. Is it possible to have a popup message when just a specific option is selected?

I.e. in the select list below, people can select low or medium without getting a warning, but if they select High, a popup warning appears?
<script>
function popup () {
alert(\'Only select high prority if this is currently stopping you from working\');
}
</script>

<select name="level">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high" onClick="popup()">High</option>
</select>

Many thanks

Ben

rangana
12-08-2008, 02:26 PM
This one is erroneous:


alert(\'Only select high prority if this is currently stopping you from working\');


You should remove highlighted.

If your intention is to alert the message with quotes on it, then you should add highlighted:


alert('\'Only select high prority if this is currently stopping you from working\'');


Alternatively, you might find another way to skin a cat:


<script type="text/javascript">
function popup (el)
{
if(el.value.toLowerCase()=='high')
alert('\'Only select high prority if this is currently stopping you from working\'');
}
</script>

<select name="level" onchange="popup(this)">
<option value="low">Low</option>
<option value="medium">Medium</option>
<option value="high">High</option>
</select>


Hope that helps.

bjblackmore
12-08-2008, 03:16 PM
Hi rangana,

Thanks for the reply.

That seems to have done the trick.

Ref the backslashes, that was a posting error. I'm programming Java/HTML inside a PHP page, and needed to use the backslash to cancel out the single quote in the javascript. I forgot to remove it when I copy & pasted the code.

Thanks again

Ben



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum