Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #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.
Reply With Quote
  #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

Reply With Quote
  #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
Reply With Quote
  #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


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 10:44 AM
populate drop down list with a function code3hree Javascript 1 May 28th, 2005 11:44 AM



All times are GMT -4. The time now is 07:30 PM.


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