Forum Moderators: open

Message Too Old, No Replies

<option>

change values

         

WhosAWhata

10:33 pm on Apr 17, 2004 (gmt 0)

10+ Year Member



<form name=form>
<input type=text name=text>
<br>
<select>
<option onblur="document.form.text.value='1'">1</option>
<option onblur="document.form.text.value='2'">2</option>
<option onblur="document.form.text.value='3'">3</option>
<option onblur="document.form.text.value='4'">4</option>
<option onblur="document.form.text.value='5'">5</option>
</select>
</form>

WhosAWhata

1:24 am on Apr 18, 2004 (gmt 0)

10+ Year Member



this code doesn't work, any ideas?

tedster

6:49 am on Apr 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think we need a bit more detail - what do you want the code to do?

Solution1

12:50 pm on Apr 18, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Try

<form name=form>
<input type=text name=text>
<br>
<select onclick="document.form.text.value=this.value">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</form>

pageoneresults

2:07 pm on Apr 18, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Or something like this...

<form method="post" name="form" action="" onsubmit="return false;">
<input type="text" name="text">
<select onchange="location.href=this.value;">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
</select>
</form>

WhosAWhata

4:50 pm on Apr 18, 2004 (gmt 0)

10+ Year Member



the problem is that this code is a watered down piece of what is in a javascript, so the real code looks more like this

<form name=form>
<input type=hidden name=text>
<br>
<select>
<option value="31" onblur="document.form.text.value='1'">1</option>
<option value="28" onblur="document.form.text.value='2'">2</option>
<option value="30" onblur="document.form.text.value='3'">3</option>
<option value="31" onblur="document.form.text.value='4'">4</option>
<option value="30" onblur="document.form.text.value='5'">5</option>
</select>
</form>

WhosAWhata

4:51 pm on Apr 18, 2004 (gmt 0)

10+ Year Member



the javascripts make use of the value is more or less what i have trouble with, it there another way to make this work?

WhosAWhata

4:58 pm on Apr 18, 2004 (gmt 0)

10+ Year Member



i was thinking something more like

<form name=form>
<input type=text name=text>
<br>
<select name=select onChange="document.form.text.value=document.form.select.option.id">
<option id="1" value="30">1</option>
<option id="2" value="28">2</option>
<option id="3" value="40">3</option>
<option id="4" value="60">5</option>
<option id="5" value="454">6</option>

</select>
</form>

it still doesn't work, but maybe it is closer?

Solution1

5:10 pm on Apr 18, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



How come you have trouble using the select box's value? As far as I know, you have no option but to use it.

WhosAWhata

11:52 pm on Apr 18, 2004 (gmt 0)

10+ Year Member



i can't use the value atribute because it is being used for a javascript function

Solution1

5:04 am on Apr 19, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



You mean that you really need two values per option, to be used in two different functions?

What you could do is this:
Have numbers as values in the options, and translate them using arrays to what the functions need.

For example:

<script type="text/javascript">
var arrayOne = new Array()
arrayOne[1]="One"
arrayOne[2]="Two"
arrayOne[3]="Three"
arrayOne[4]="Four"
arrayOne[5]="Five"

var arrayTwo = new Array()
arrayTwo[1]="some location"
arrayTwo[2]="some other location"
arrayTwo[3]="some url"
arrayTwo[4]="some uri"
arrayTwo[5]="some address"

function someFunction() {
alert(arrayTwo[document.frm.sel.value])
}
</script>

<form name="frm" onsubmit="someFunction(); return false;">
<input type="text" name="text">
<br>
<select name="sel" onchange="document.frm.text.value=arrayOne[this.value];">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" value="Submit">
</form>

WhosAWhata

10:19 pm on Apr 19, 2004 (gmt 0)

10+ Year Member



will this work if option values repeat?
<option value=31>Jan</option>
<option value=28>Feb</option>
<option value=31>Mar</option>
<option value=30>Apr</option>
<option value=31>May</option>
<option value=30>Jun</option>
<option value=31>Jul</option>
<option value=31>Aug</option>
<option value=30>Sep</option>
<option value=31>Oct</option>
<option value=30>Nov</option>
<option value=31>Dec</option>

example has value set to the number of days in each month, so the only values are 29, 30, and 31

Solution1

5:27 am on Apr 20, 2004 (gmt 0)

10+ Year Member Top Contributors Of The Month



Sure, that'll work. There's no requirement that values be unique.

WhosAWhata

10:34 pm on Apr 20, 2004 (gmt 0)

10+ Year Member



well in that case, does anyone have any ideas on how to intigrate that with this script?

[webmasterworld.com...]