...

View Full Version : Get value from a <select>



Zynex
02-19-2007, 12:16 PM
I was wondering. Is it possible to retrieve the value of a select. I have a select with all the months of the year.

<select name="selection">
<option>januari</option>
<option>Februari</option>
<option>Maart</option>
<option>April</option>
<option>Mei</option>
<option>Juni</option>
<option>Juli</option>
<option>Augustus</option>
<option>September</option>
<option>Oktober</option>
<option>Novermber</option>
<option>December</option>
</select>

When someone chooses for instance "februari" I want that value to be given to an <input type="text" name="invoer">

I tried things like

invoer.value = selection.value;

But that did not work. How do I get this value??

Thanx in advance,

Zynex

vwphillips
02-19-2007, 02:09 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>
<title></title>
<script language="JavaScript" type="text/javascript">
<!--
var MonthAry=['januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','Novermber ','December'];

function Populate(frm,sel,ary){
for (var zxc0=0;zxc0<ary.length;zxc0++){
document[frm][sel].options[zxc0+1]=new Option(ary[zxc0],ary[zxc0],true,true);
}
document[frm][sel].selectedIndex=0;
}

function Write(sel,tb){
sel.form[tb].value=sel.value;
}

//-->
</script></head>

<body onload="Populate('MyForm','selection',MonthAry);" >

<form name="MyForm" >
<select name="selection" onchange="Write(this,'monthtxt');" >
<option value="" >Select Month</option>
<input name="monthtxt" type="text" size="10" >
</select>
</form>
</body>

</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum