View Full Version : How to take a value from a Select Box

07-11-2006, 02:03 PM
ok so a select box (<select name="blabla"><option>bla</option</select) how do i trap the option selected (onClick event) and place the value selected into a text box? I am a PHP programmer and the page refresh issue gets in the way of what i need to accomplish, javascript can do it!


07-11-2006, 02:16 PM
You can use the onchange event handler, try this:

<script type="text/javascript">
function move(sel, txt)
txt.value = sel.options[sel.selectedIndex].value;
<select name="test" onchange="move(this, txt);">
<option value="boo1">boo1</option>
<option value="boo2">boo2</option>
<option value="boo3">boo3</option>
<option value="boo4">boo4</option>
<input type="text" name="txt">

Good luck;

07-11-2006, 06:57 PM

One question though, the function "move()" in the onchange="move(this, txt)" what is "this"?? its not defined anywhere

07-11-2006, 07:36 PM
'this' refers to the select element. It would be the same as passing it's name to the function.
Heres a good reference:

Good luck;

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum