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

SELECT <option value..>

Hi,

in my SELECT (like below), the option value has 2 values, separated with
comma ","

<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

How can I read these two values individually from Javascript statement ?
like one is 10, another one is John

i.e document.form.option[document.form.selectedIndex].value ?
thanks.

Mar 17 '07 #1
4 10324

"magix" <ma***@asia.comwrote in message
news:45**********@news.tm.net.my...
Hi,

in my SELECT (like below), the option value has 2 values, separated with
comma ","

<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

How can I read these two values individually from Javascript statement ?
like one is 10, another one is John

i.e document.form.option[document.form.selectedIndex].value ?
thanks.

and also how can I use document.getElementById('sIdname').value to retrieve
10 and John? (Assume <Select name="sIdName" id="sIdName"..>, some sort of
split function need to be done.
Mar 17 '07 #2
magix said the following on 3/17/2007 5:28 AM:
Hi,

in my SELECT (like below), the option value has 2 values, separated with
comma ","
No, it has one value that contains a comma.
<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

How can I read these two values individually from Javascript statement ?
like one is 10, another one is John

i.e document.form.option[document.form.selectedIndex].value ?
var selectValue = document.forms['formName'].elements['selectName'].value
var theArray = selectValue.split(',')
var firstValue = theArray[0]
var secondValue = theArray[1]

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Mar 17 '07 #3
magix wrote on 17 mrt 2007 in comp.lang.javascript:
Hi,

in my SELECT (like below), the option value has 2 values, separated
with comma ","

<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

How can I read these two values individually from Javascript statement
? like one is 10, another one is John

i.e document.form.option[document.form.selectedIndex].value ?
It pays to read the specs:
selectedIndex is no child of form but of the select.
form is not the same as forms[0].

use:
============================
<form>
<select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva" selected>Eva</option>
<option value="22,Danny">Danny</option>
</select>
</form>

<script type='text/javascript'>

var r = document.forms[0].elements['sIdName']
var rr = r.options[r.selectedIndex].value.split(',');

alert(rr[0]); // 11
alert(rr[1]); // Eva

</script>
============================

or:
============================
<select name="sIdName" onchange='chd(this)'>
<option value="--,--">-- ? --</option>
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

<script type='text/javascript'>

function chd(r) {
if (r.selectedIndex==0) return;
var rr = r.options[r.selectedIndex].value.split(',');
alert(rr[0]);
alert(rr[1]);
};

</script>
============================

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Mar 17 '07 #4

"Randy Webb" <Hi************@aol.comwrote in message
news:DN********************@giganews.com...
magix said the following on 3/17/2007 5:28 AM:
>Hi,

in my SELECT (like below), the option value has 2 values, separated with
comma ","

No, it has one value that contains a comma.
> <select name="sIdName">
<option value="10,John">John</option>
<option value="11,Eva">Eva</option>
<option value="22,Danny">Danny</option>
</select>

How can I read these two values individually from Javascript statement ?
like one is 10, another one is John

i.e document.form.option[document.form.selectedIndex].value ?

var selectValue = document.forms['formName'].elements['selectName'].value
var theArray = selectValue.split(',')
var firstValue = theArray[0]
var secondValue = theArray[1]

--
Randy
Chance Favors The Prepared Mind
comp.lang.javascript FAQ - http://jibbering.com/faq/index.html
Javascript Best Practices -
http://www.JavascriptToolbox.com/bestpractices/

Thank you. Case Closed.
Mar 17 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Michael Hoffmann | last post by:
Hello, As you might guess I am completely new to this language. Maybe I get some help here. I try to execute a user defined funciton from a select option in a document to read a file into an...
3
by: J. Muenchbourg | last post by:
I have an ASP admin script where I'm adding records, and I have a category that already has set name values hard-coded into a selct option pulldown, but if the user wants to create a new category...
1
by: Robert Kattke | last post by:
I'm designing a site for local music and entertertainment and have a few ?s that need to be cleared up. Currently, I'm working on the Club part and have a Contact Person form, and a Club form. ...
4
by: Old Lady | last post by:
Hi, I need help! I have a SELECT/OPTION list. My goal is to have a TEXT input field in a form that is normally disabled, but it should become enabled when the user select one predefined OPTION....
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...
1
by: kirke | last post by:
I want to load textarea's value in drop-down box. In first page, such form is existed. <form name="form1" method="post" action="next.php"> <textarea name="dayList" Id = "dayList" cols=20...
3
by: ajay2552 | last post by:
Hi, I have a query. All html tags start with < and end with >. Suppose i want to display either '<' or '>' or say some text like '<Company>' in html how do i do it? One method is to use &lt,...
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...
3
by: pravinnweb | last post by:
Hi i have select option in my page which works fine in firefox in which i mention specific width for select option when i clicked select list the option lengths are large the option area is expanded...
7
by: fsalvador | last post by:
Hi, I am trying to figure it out how to to hide in onmouseout the select options of a form. Below is the code I got so far. It isn't working. Please help. Thanks <!DOCTYPE HTML PUBLIC...
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: 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
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
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
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...
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...

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.