473,322 Members | 1,398 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,322 software developers and data experts.

how to get <option> id

hey every body

how can i get using javascript the selected option <option> ID or Value because when ever i clicked it i get the <select> id and i dont want that

[HTML]<select name="list" id="list" size="10%" >
<option id="3" ondblclick="select_song();">Apple
<br> </option>
<option id="4" ondblclick="select_song();">Orange
<br> </option>
<option id="5" ondblclick="select_song();">Banana<br> </option>
<option id="6" ondblclick="select_song();">lemon<br> </option>
</select>[/HTML]

Expand|Select|Wrap|Line Numbers
  1. function select_song()
  2. {
  3.     var i = event.srcElement.id
  4.                alert(i); // this give me an alert (list)
  5.  
  6. }
Jun 25 '08 #1
9 5759
r035198x
13,262 8TB
Why not just go through a Javascript tutorial to find out how to use a select?
Jun 25 '08 #2
i can teach you how to use javascript and if you dont know the answer plz dont replay

and dont be disrespectial cuz u r an admin

thanks anyway
Jun 25 '08 #3
r035198x
13,262 8TB
i can teach you how to use javascript and if you dont know the answer plz dont replay

and dont be disrespectial cuz u r an admin

thanks anyway
It's not that I want to be disrespectful.
We just have some rules on this forum which unfortunately I have to enforce.
Giving you the code makes your current problem go away but reading a tutorial makes future potential problems go away as well. There are also lots of threads in this forum which can give you the answer, but I still prefer that you read a Javascript tutorial on how to use a select.

Reading, unfortunately has become a lost art.
Jun 25 '08 #4
hsriat
1,654 Expert 1GB
I guess it too hot these days.. month of July approaching.. I hate it. I have ordered some soft drinks for you guys.

While we are waiting for the drinks, let me look into the JavaScript problem.
Expand|Select|Wrap|Line Numbers
  1. var list = event.srcElement;
  2. alert(list.options[list.selectedIndex].id);
I didn't test it. But I think it should work.

You may also read this tutorial.
Jun 25 '08 #5
r035198x
13,262 8TB
I guess it too hot these days.. month of July approaching.. I hate it. I have ordered some soft drinks for you guys.

While we are waiting for the drinks, let me look into the JavaScript problem.
Expand|Select|Wrap|Line Numbers
  1. var list = event.srcElement;
  2. alert(list.options[list.selectedIndex].id);
I didn't test it. But I think it should work.

You may also read this tutorial.
July is winter for us.

P.S You just gave someone fish instead of teaching them how to fish. Better stick around in case they run out of the fish that you gave them.
Jun 25 '08 #6
hsriat
1,654 Expert 1GB
July is winter for us.

P.S You just gave someone fish instead of teaching them how to fish. Better stick around in case they run out of the fish that you gave them.
umm.. then you must be in Aus or NZ I guess. Or somewhere in Southern Hemisphere.

And I linked a small tutorial too to let him know how I fish.

Regards,
Harpreet [ doen't not really intend to hurt anyone :) ]
Jun 25 '08 #7
acoder
16,027 Expert Mod 8TB
srcElement is IE-only. target is the standard, so you'll have to use a combination to support all browsers.

One more problem: IDs shouldn't begin with numbers.

Note also that IE treats the options as part of the select (can be annoying), but not all browsers do.
Jun 25 '08 #8
I guess it too hot these days.. month of July approaching.. I hate it. I have ordered some soft drinks for you guys.

While we are waiting for the drinks, let me look into the JavaScript problem.
Expand|Select|Wrap|Line Numbers
  1. var list = event.srcElement;
  2. alert(list.options[list.selectedIndex].id);
I didn't test it. But I think it should work.

You may also read this tutorial.
thanks hsriat

it works and thanks for the tutorial ,,,,
Jun 26 '08 #9
hsriat
1,654 Expert 1GB
thanks hsriat

it works and thanks for the tutorial ,,,,
As acoder said, srcElement is an IE thing. So you better call that function with an argument which refers to the select box.
selectSong(this.parentNode)
Jun 26 '08 #10

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

Similar topics

2
by: Andrea | last post by:
Hi, I'm trying to emulate part of our client-server application as a web site so customers can use it, and I'm stuck when it comes to re-ordering items in a list. Basically we have a list of...
1
by: Ang Talunin | last post by:
Hey, I wondering if it's possible to retrieve all the <option>-fields from a <select> when posting a <form> to a php file Example: I've got a form like this: <form action = phpfile.php...
6
by: Chris Fink | last post by:
Does anyone know it is possible to include a small image(.gif .jpeg) within a <SELECT><option> so that the user would see the option text as well as a little image(icon) in the option? I know this...
6
by: joseph.lindley | last post by:
Forgive me for I am a bit of a web-dev novice - but I'm not doing too bad. I'm currently working with a bit of javascript to dynamically add <option>s into a select box. My code currently works...
1
by: frey | last post by:
i tried to create a dropdown menu and use the option as a control to change content inside another text area the code is like this: <select name="xxxx"><option onclick="changeunitprice(29.87)"...
4
by: Man-wai Chang | last post by:
-- iTech Consulting Co., Ltd. Expert of ePOS solutions Website: http://www.itech.com.hk (IE only) Tel: (852)2325 3883 Fax: (852)2325 8288
7
by: Shrek | last post by:
I have a drop down on a web page and want to change the cursor from default to pointer, so my style definition has style ="cursor: pointer;" the drop down though fails to change from the...
4
by: pplers | last post by:
Here is config.php: <?php //The vars are all ok. $dbhost = 'localhost'; $dbname = 'forum'; $dbuser = 'toor'; $dbpass = ''; ?> Here is a part of functions.php: <? require "config.php"; //It...
14
by: The Natural Philosopher | last post by:
This is a nasty one and I can't see my way out of it. I have a bunch of select statements in a form, and each select statement has an onchange="do_something(this)" in it, and this works...
14
mikek12004
by: mikek12004 | last post by:
In a form I have 5 elements (e.g. pictures) and I wish for the user to be able to set the order of appearance. For this I have for each picture a select box (names select1 to select5) with "please...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.