473,473 Members | 1,735 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Drop down list value using javascript

119 New Member
Hi

I am using php and smarty, what i have to do is i have a drop down box with dynamic name, id and values.

like
Expand|Select|Wrap|Line Numbers
  1. <select name="id[{$options_data.ID}]" id="id[{$options_data.ID}]" onchange="sample()" >
  2.   {foreach key=key_data item=item_data from=$options_data.DATA}
  3.   <option value="{$item_data.ID}">{$item_data.TEXT} {if $item_data.PRICE !='' }{$item_data.PREFIX} {$item_data.PRICE}{/if} </option>
  4. {/foreach}
  5. </select>
  6.  
I want to take one value form that and i have to show in alert box, i tried some method but no use.

Ex :
Expand|Select|Wrap|Line Numbers
  1. <select name ="id[{$options_data.ID}]" id="id[{$options_data.ID}]" onchange="sample()>
  2. <option value="45">value 1</option>
  3. <option value ="46">value 2</option>
  4. </select>

Javascript code on top of the html page:
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function sample()
  3. {
  4.  var id = document.getElementById("id[3]");
  5.  
  6.  alert("The content of the first " + "\"" + id.innerHTML + "\".");
  7. }
  8. </script>
  9.  
But this showing all the values in the drop down box. i want to take only one value from the drop down..

can anyone help me what will be the correction in this please.

regards
magesh
Jan 9 '09 #1
4 7003
xNephilimx
213 Recognized Expert New Member
If "one value" means, "the selected option's inner html", you shoud do this:

Expand|Select|Wrap|Line Numbers
  1. id.options[id.selectedIndex].innerHTML
  2.  
if you need the value, just change the innerHTML part with value.
Jan 9 '09 #2
acoder
16,027 Recognized Expert Moderator MVP
Note that IDs should not have [], so remove them and access as "id3".
Jan 9 '09 #3
phpmagesh
119 New Member
@xNephilimx

Hi

Every time my id will be changed depends on the selection of category.

Example

Expand|Select|Wrap|Line Numbers
  1. some time i will get that as <select name="id[3]" id="id[3]">
  2.  
some times i will get id[4], id[5], id[6] etc...

so my select option name is not constant.

now the problem is i want to take that name to that sample() function

that name="id[{$options_data.ID}]". in this {$options_data.ID} is smarty value comes form php page i just want the values which is in select name


Can anyone help me in this please.

Regards
magesh
Jan 10 '09 #4
acoder
16,027 Recognized Expert Moderator MVP
For the ID use:
Expand|Select|Wrap|Line Numbers
  1. <select id="id{$options_data.ID}" onchange="sample()" >
Then in the JavaScript code
Expand|Select|Wrap|Line Numbers
  1. function sample()
  2. {
  3.  var id = document.getElementById("id{$options_data.ID}").value;
if it's on the same page.
Jan 10 '09 #5

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

Similar topics

4
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by...
1
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the...
3
by: Stephen Adam | last post by:
Hi there, I'm sure i'm missing something really simple here, all i want to do is get the value of the selected item in a list box. Even after much fiddling about last night I still could not get...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
3
by: John Walker | last post by:
Hi, On an ASP.NET page I have a drop down list control. When the user pulls down the list and makes a selection, I perform validation, and if the validation fails I want the selected item in...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
0
by: weiwei | last post by:
Hi here is my scenario, I create a drop down list in itemtemplate.(that drop down is created from db), after user click edit command, my ideal plan is have another drop down list in...
3
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the...
1
by: deerick | last post by:
Hi there I want to know how to add a drop down list based on value from a table in an asp form. Then I want the user to be able to submit the form, and the drop down list value that they have...
15
by: ajos | last post by:
Hello all, Im making a dependent drop down for my application for filtering purpose. I have populated the drop down from the database and retrieved in the html. <tr> <td valign="top"...
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
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
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.