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

Other Values Retrieved from Select

I wanted to add additional data to my select function.

I tried:

<select id="sel_1" name="sel_1" onChange="dispSel(this);">
<option struct_id="24" value="4">Text 1</option>
<option struct_id="37" value="8">Text 2</option>
</select>

function dispSel(obj)
{
alert(obj.struct_id);
}

This did not work. I'd like to be able to add some other data
associated with the option in the select element.

Anyone have any other ideas.

One I thought of was instead of
<option struct_id="24" value="4">Text 1</option>
use
<option value="24|4">Text 1</option>

and then
function dispSel(obj)
{
var myarray=obj.value.split("|");
alert(myarray[0]);
}

Any help is appreciated.

Mike

Jul 23 '05 #1
4 1282
mike wrote on 13 mrt 2005 in comp.lang.javascript:
One I thought of was instead of
<option struct_id="24" value="4">Text 1</option>
use
<option value="24|4">Text 1</option>

and then
function dispSel(obj)
{
var myarray=obj.value.split("|");
alert(myarray[0]);
}


A good thought:

<select
onChange="alert(this.value.split(',')[1]);">
<option value="4,37">Text 4</option>
<option value="8,39">Text 8</option>
</select>
--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Jul 23 '05 #2
> <option struct_id="24"....
alert(obj.struct_id);
You might be able to get this to work using getAttribute, perhaps only
on some browsers. Look up attribute handling on Quirksmode. It is not
a good solution.
<option value="24|4">
var myarray=obj.value.split("|");
alert(myarray[0]);


Yes, this is a good way to do it.

Something that I thought of recently was this:

<select onchange="eval(this.value)">
<option value="javascript code here...">

The code in the value attribute could set variables, call functions
etc.
This might be a useful technique in a few situations.

--Phil.

Jul 23 '05 #3
mike wrote:
I wanted to add additional data to my select function.

I tried:

<select id="sel_1" name="sel_1" onChange="dispSel(this);">
<option struct_id="24" value="4">Text 1</option>
<option struct_id="37" value="8">Text 2</option>
</select>

function dispSel(obj)
{
alert(obj.struct_id);
}

This did not work. I'd like to be able to add some other data
associated with the option in the select element.

Anyone have any other ideas.

One I thought of was instead of
<option struct_id="24" value="4">Text 1</option>
use
<option value="24|4">Text 1</option>

and then
function dispSel(obj)
{
var myarray=obj.value.split("|");
alert(myarray[0]);
}

Any help is appreciated.

Mike


http://www.alistapart.com/articles/scripttriggers/

Jul 23 '05 #4
> I wanted to add additional data to my select function.
I tried:
<select id="sel_1" name="sel_1"
onChange="dispSel(this);">


It didn't work because you sent the entire select object, instead of
the selected option:

<select id="sel_1" name="sel_1"
onChange="alert(this.options[this.selectedIndex].struct_id);">
<option struct_id="24" value="4">Text 1</option>
<option struct_id="37" value="8">Text 2</option>
</select>

Kev

Jul 23 '05 #5

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

Similar topics

2
by: John Wilson | last post by:
Hello friends, I have this dynamic array(shown below) that I need to match to values (1 - 10) that I am returning from the database via DSN connection object. The values I need to match are on...
16
by: Tim Davidge | last post by:
Hi folks, been a while since I have posted a plea for help and I think I have forgotten everything I learnt from the helpful contributors to this newsgroup, that said however : I'm trying to...
4
by: Jack | last post by:
THE FOLLOWING IS A PART OF CODE FROM A ASP PAGE <% sql01 = "SELECT COUNT(*) AS reccount FROM Equipmenttbl " sql01 = sql01 & "WHERE Equipmenttbl.GrantID = " & GrantID 'Response.Write sql01 &...
12
by: Jack | last post by:
Since, I have not got some desired advise, I am reposting this for some asnwer/valuable suggestion. Thanks. THE FOLLOWING IS A PART OF CODE FROM A ASP PAGE <% sql01 = "SELECT COUNT(*) AS...
5
by: Neil | last post by:
I'd like to know what the best method is for handling NULL (or 0) values within a DropDownList. If a database lookup value is optional I would normally consider leaving it NULL but this leads to...
4
by: Marc DVer | last post by:
As a simple example, say there is table 'namelist' with column 'names' as char(20). I would like to do something akin to: select namelist.names as mynames, left(mynames,2) as initials; In...
6
by: Steve | last post by:
I realize that this probably isn't a best practice, but I'm working with legacy code that has a query stored in one column of a table. Because the queries vary, the JSP page that selects a query...
2
by: Hyun-jik Bae | last post by:
Is there any way to prohibit writing values to an object A retrieved from another object B if B gives A for read only purpose? For example, public class B { public int xx; }
4
by: jith87 | last post by:
Hi, I ve retrieved values from MySql db. From the result set i ve used the getXXX() to get the values in seperate variables. Earlier i used getParameter() to get the values from JSP page to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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?
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
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...

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.