Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alert when option from dropdown menu is selecteed

Status
Not open for further replies.

leonk09

Technical User
Nov 9, 2005
20
GB
hi all,

I really don't know much about javascripts (I know how to cut an paste them, but not much else).

I have a mail form, which already has plenty of javascript on there for validation.

One of the sections of my form is a dropdown menu. I need an alert box with a message to appear when a specific value is selected:

Here's the dropdown menu:

<SELECT name="lst_fn_9">
<option value="NOT SELECETED" selected>Please Select</option>
<option value="value 1" >Value 1</option>
<option value="Value 2" >Value 2</option>

So say for example somebody selects "value 2", I want an alert window to appear immedialtey on selection.

How would I go about doing this?

many thanks
 
use the onchange handler on the select box:

Code:
<script type="text/javascript">

function msg(obj) {
   if (obj.selectedIndex == 2) {
      alert("you have selected option 2");
   }
}

</script>
<select name="lst_fn_9" [b][COLOR=red]onchange="msg(this)"[/color][/b]>
<option value="NOT SELECETED" selected>Please Select</option>
<option value="value 1" >Value 1</option>
<option value="Value 2" >Value 2</option>
</select>

-kaht

How much you wanna make a bet I can throw a football over them mountains?
sheepico.jpg
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top