473,406 Members | 2,378 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

how to call onselect event dropdownlist

when i have select itemfrom dropdownlist i want to call javascript function
Sep 27 '07 #1
6 30151
gits
5,390 Expert Mod 4TB
hi ...

use the onchange-event of the <select> - element to invoke a function with the value of the control:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function show_value(val) {
  3.     alert(val);
  4. }
  5. </script>
  6.  
  7. <select name="test" onchange="show_value(this.value);">
  8.     <option value="a">a</option>
  9.     <option value="b">b</option>
  10.     <option value="c">c</option>
  11. </select>
kind regards
Sep 28 '07 #2
bond26
1
Hallo guys

what if you have code like one below and want to use onselect

Expand|Select|Wrap|Line Numbers
  1.         <?php
  2.  
  3.               echo "<select name='states'  onclick='getClientData(this)' >\n";
  4.               echo "<option value=''>==== choose title ====</option>\n";
  5.               $result=mysql_db_query($db_name,"select `template_id`, `template_detail`,`template_desc` from tbl_templates ");
  6.               while(list($id, $name,$detail)=mysql_fetch_array($result)){
  7.                    echo "<option value=\"$id\" >$detail</option> \n" ;
  8.               }
  9.              echo "</select>\n";
  10.  
  11.             ?>
  12.  
help please
Feb 1 '08 #3
gits
5,390 Expert Mod 4TB
hi ...

please explain it in more detail ... what should happen? your current code always calls getClientData() when you click that control ... so what do you want to achieve instead or additionally?

kind regards
Feb 1 '08 #4
acoder
16,027 Expert Mod 8TB
Moved to JavaScript forum.
Feb 4 '08 #5
you can use this code i hope it will help for you.

Expand|Select|Wrap|Line Numbers
  1. <select id="ddlFruits" onchange="GetSelectedTextValue(this)">
  2.     <option value=""></option>
  3.     <option value="1">Apple</option>
  4.     <option value="2">Mango</option>
  5.     <option value="3">Orange</option>
  6. </select>
  7. <script type="text/javascript">
  8.     function GetSelectedTextValue(ddlFruits) {
  9.         var selectedText = ddlFruits.options[ddlFruits.selectedIndex].innerHTML;
  10.         var selectedValue = ddlFruits.value;
  11.         alert("Selected Text: " + selectedText + " Value: " + selectedValue);
  12.     }
  13. </script>
Thank you.
Jul 10 '19 #6
gits
5,390 Expert Mod 4TB
if the options do have a value property this solution is definitivly inferior because of the many more operations and the solution i gave in post #2 is the one to prefer.
Jul 10 '19 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: F. Da Costa | last post by:
Hi, Does the following indeed imply that this event is NOT called when an <input type="checkbox" is toggled? This would thus imply the usage of the onClick handler instead (assuming an action...
6
by: Hal Vaughan | last post by:
I'm using KDE on Linux, with Konqueror as the testing browser for this project. I've recently upgraded, so I realize some of the bugs I'm dealing with may or may not be my program, and could also...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Martin | last post by:
Does somebody knows, if there's a way to call the OnSelectedIndexChanged method of the dropdownlist by myself? Or does somebody knows a way, to raise the SelectedIndexChanged Event of a...
1
by: Lucifer | last post by:
Hi I am trying to raise a bubble event. I have a dropdownlist and a datalist in a datalist. I want to use the postback from the dropdownlist to rebind the nested datalist. But i need the...
6
by: Olivier Matrot | last post by:
Hello, This has probably been asked several times, but It must be clarified for me. I would like to know why sometimes during a postback Page_Load is called after the function marked for...
2
by: glenn | last post by:
Hi folks, I am trying to determine which item in a DropDownList Web control has been selected. I have posted an OnSelectedIndexChanged subroutine in my code with a reference to the subroutine...
11
by: J055 | last post by:
Hi I have a dropdown control which is constructed in another dropdown control SelectedIndexChanged event protected void ddlParamType_SelectedIndexChanged(object sender, EventArgs e) { //...
3
by: Ignacio Machin | last post by:
How can I call an event from another event: I want to call : DropDownList_SelectedIndexChanged in: Page_Load
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.