473,396 Members | 2,010 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,396 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 30149
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.