p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Javascript How-To (http://p2p.wrox.com/forumdisplay.php?f=87)
-   -   Java script function on drop down list selection (http://p2p.wrox.com/showthread.php?t=28002)

Sachin3k April 12th, 2005 01:42 AM

Java script function on drop down list selection
 
Hi all,
 can anybody tell me how can call
java script function on drop down list selection.

ChrisScott April 14th, 2005 04:36 AM

You can use the onchange event....
Code:

<select onchange="myFunc();">
HTH,

Chris


crmpicco April 14th, 2005 08:32 AM

onFocus may work too

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt

interrupt April 30th, 2005 11:30 AM

You should also be able to have a function 'per item selected' using the selectedIndex method. So you'd have a function called by the onchange event, then depending on the selection made, another function being called.

ie:

<form name ="form1">
<select name ="sel1" onchange ="myFunction()">
<option value ="0">0
<option value ="1">1
<option value ="2">2
</option>
</select>

<script language ="javascript">
function myfunction(){
var theSelection = document.form1.sel1.selectedIndex

if (theSelection ==0){
function0()
}
elseif (theSelection ==1){
function1()
}
elseif (theSelection ==2){
function2()
}
}
function0(){
alert("I was called from function 0")
}
function1(){
alert("I was called from function 1")
}
function2(){
alert("I was called from function 2")
}

</script>

Hope that helps! (Haven't tested yet, but it looks ok)

interrupt




All times are GMT -4. The time now is 07:21 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.