Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 12th, 2005, 01:42 AM
Registered User
 
Join Date: Apr 2005
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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.
  #2 (permalink)  
Old April 14th, 2005, 04:36 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

You can use the onchange event....
Code:
<select onchange="myFunc();">
HTH,

Chris

  #3 (permalink)  
Old April 14th, 2005, 08:32 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

onFocus may work too

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
  #4 (permalink)  
Old April 30th, 2005, 11:30 AM
Friend of Wrox
 
Join Date: May 2004
Location: , , .
Posts: 212
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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




Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting itme from drop down list in script hericles ASP.NET 1.0 and 1.1 Basics 7 August 21st, 2007 01:21 PM
java script function nalla ASP.NET 2.0 Professional 2 June 22nd, 2006 05:00 AM
Java script function is not calling in Mozilla mouli_sam ASP.NET 1.0 and 1.1 Professional 0 May 9th, 2006 01:44 AM
Populating web form with drop down list selection AugieDawgie ASP.NET 1.0 and 1.1 Basics 0 December 7th, 2005 11:44 AM
populate drop down list with a function code3hree Javascript 1 May 28th, 2005 11:44 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.