Forum Moderators: open

Message Too Old, No Replies

Getting multiple values from an <option>

         

j4mes

6:33 pm on May 13, 2004 (gmt 0)

10+ Year Member



Does anyone know how I can pull more than one value from a

<form>
<select>
<option value="x">Option X</option>
</select>
</form>

<script>
document.write(document.form.select.value);
</script>

type setup?

Basically, I want to have a document.form.select.another_value so that one option can pass more than one value for Javascript to play with.

Presumably this is fairly easy to do, but as I've never needed it before it's something I've never worried about.

Thanks.

coopster

6:39 pm on May 13, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



<select multiple [w3.org]="multiple">

j4mes

6:42 pm on May 13, 2004 (gmt 0)

10+ Year Member



Sorry, I should have been more specific. I only want to select one option but have it pass two different values to a script to be used independently.

Thanks.

DrDoc

6:53 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Two different values? What do you mean?

j4mes

7:05 pm on May 13, 2004 (gmt 0)

10+ Year Member



I mean like

<option value_one="x" value_two="y">Option X and Y</option>

document.do_one_thing(document.form.select.value_one);
document.do_some_other_thing(document.form.select.value_two);

.. if you see what I mean.

Selecting one option gives me two separate values to do different things to.

If it helps, I can post my script as it is so far.

Much appreciated.

James.

DrDoc

7:07 pm on May 13, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<option value="foo¦bar">

Then just split() the value at the ¦ and you end up with two :)
Other than that -- no, you can't assign two values to an option.

j4mes

7:12 pm on May 13, 2004 (gmt 0)

10+ Year Member



Nice one, thanks.

So what's the necessary code to let me

document.write(document.form.select.foo);
document.write(document.form.select.bar);

I'm not familiar with split(), but it sounds very useful.

Thanks DrDoc.

j4mes

7:47 pm on May 13, 2004 (gmt 0)

10+ Year Member



Ok, Googled for it, here's a split() tutorial for anyone who finds this in the future with a similar question.

[pageresource.com...]

Thanks DrDoc for all your help.

-- James