/    Sign up×
Community /Pin to ProfileBookmark

Popup Message When Specific Option Selected

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 () {
if (this.level=2) {
alert(‘Only select high prority if this is currently stopping you from working’);
}
}
</script>

<select name=”level”>
<option value=”0″>Low</option>
<option value=”1″>Medium</option>
<option value=”2″ onClick=”popup()”>High</option>
</select>

Many thanks

Ben

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@mikemDec 08.2008 — Hi Ben,

You can pass the value of the selected item to a function for comparison each time the selection gets changed...

<script>

function popup(n)

{

if ( n === 2 )

{

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

}

}

</script>

<select name="level" onchange="popup(this.options.selectedIndex)">

<option value="0">Low</option>

<option value="1">Medium</option>

<option value="2" >High</option>

</select>

Mike
Copy linkTweet thisAlerts:
@vwphillipsDec 08.2008 — [CODE]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
/*<![CDATA[*/

function popup(sel){
if (sel.selectedIndex==2){
var ok=confirm('Did you want to select High');
if (ok){
alert('yes');
}
else {
alert('no');
}

}
}
/*]]>*/
</script></head>

<body>
<select name="level"onClick="popup(this)">
<option value="0">Low</option>
<option value="1">Medium</option>
<option value="2" >High</option>
</select>

</body>

</html>[/CODE]
×

Success!

Help @bjblackmore spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...