Online Shopping : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

20 of 27 people (74%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How Can I Pass Value TextBox to OptionBox

May 14th, 2009 12:27
tikane tinjane, ha mo, Ole Clausen, thulasi ram,


Getting the text and value from two text inputs, you can add a new 
option at the end of a dropdown like this:
<script type="text/JavaScript">
function myTrans(f) {
  f.mySel.options[f.mySel.length] = new Option();
  f.mySel.options[f.mySel.length-1].text = f.txt.value;
  f.mySel.options[f.mySel.length-1].value = f.val.value;
}
</script>
<form>
<select name="mySel">
  <option value="0">first</option>
  <option value="1">second</option>
  <option value="2">third</option>
</select>
<input type="text" name="txt">
<input type="text" name="val">
<button onclick="myTrans(this.form)">transfer</button>
</form>
===========================================================
You can even make the function a little 'sexier' like this:
function myTrans(f) {
  f.mySel.options[f.mySel.length] = new Option(f.txt.value, 
f.val.value);
}
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com
http://antworten.leblogguide.com/