Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Possible to give option-element multiple values?

Status
Not open for further replies.

torb1

Technical User
Oct 15, 2002
3
SE
I want my drop down lists to give me more than one value in return... Typically it looks like this, right?:

<option value=&quot;something&quot;>something else</option>

So what I want is something that giver me yet another 'something' so that the form element can give me more information than _just_ its selected value... possibly something like...

<option value=&quot;something&quot; value2=&quot;another something&quot;>something else</option>

Is it possible to do something like this? How?

OR...
Is there a way I can get a the &quot;item name&quot; of the value in question, sort of like replacing:

code += window.document.my_form.my_list.value

with something like

code += window.document.my_form.my_list.item.name

I've tried looking it up in all sorts of forums and books (JavaScript Bible etc) with no success, so I'd be truly greatful for any help. Credit will of course be given in the finished product to anyone who has 'the' solution.

Thanks,
-torb
 


Well, I'm not sure why you would want to do this...there may be a better wa if you want to explain why you want to do this...
but, in the meantime, the only thing I can think of that may help would be to get the name of the select.

document.my_form.my_list.name

mac
 
hi torb,

yes to both.

1. you can put multiple values in the &quot;value=&quot; attribute, separated by the delimiter of your choice...you'll need to parse/split those values yourself to take advantage of it. it's simple though:
[tt]
function splitValues(oEl) {
var vals = oEl.options[oEl.selectedIndex].value;
vals = vals.split(&quot;:&quot;);
for (x = 0; x < vals.length; x++)
alert(&quot;vals[&quot; + x + &quot;] = &quot; + vals[x]);
}

<select onchange=&quot;splitValues(this);&quot;>
<option value=&quot;eeny:meeny:miney:moe&quot;>Four values</option>
<option value=&quot;larry:curly:moe&quot;>I have three values</option>
</select>
[/tt]

2. consider the element:
[tt]<select name=&quot;sel&quot;>
<option value=&quot;foo&quot;>bar</option>
</select>

sel.options[sel.selectedIndex].value = &quot;foo&quot;;
sel.options[sel.selectedIndex].text = &quot;bar&quot;;
[/tt]

hope this helps!


=========================================================
if (!succeed) try();
-jeff
 
I'll try your suggestions tonight. As for

document.my_form.my_list.name

I believe it only writes &quot;my_list&quot; in the new window it posts to, ie. the name of the list, not the name of the item within the list :-(

For 99Miles - the purpose of the script:
The script is part of a large character sheet for an RPG called Kult. When the user selects a value for his characters &quot;ability score&quot;, he just sees a drop-down list of numbers from 1-20, these items have values that give secondary abilities (such as how much damage the character can take). So far, so good.

The problem starts when I have to add the '1-20' off all abilities ignoring when the value for each item is something different than '1-20.'

The values for the items are sent to a new window to make a custom-designed sheet. The values for the addition of the '1-20' abilities are merely there to indicate for the user wether or not he/she has any more 'points' to use (so that he/she should raise or lower the ability score).

BTW thanks, I'll try your suggestions later tonight.
-torb1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top