html - Plain Javascript Select Option -


i have dropdown 3 options , textbox. dropdown, top 1 empty , 2nd , 3rd have values. when toggled between these 3 options, managed output 2nd , 3rd value in textbox not 1st option value (i want empty textbox when option 1 selected).. how this?

check code please..

function price(){ if (document.getelementbyid("fruits").selectedindex < 1) { document.getelementbyid("fruitprice").value = "" } if (document.getelementbyid("fruits").selectedindex == 1) { document.getelementbyid("fruitprice").value = (2).tofixed(2); } if (document.getelementbyid("fruits").selectedindex == 2) { document.getelementbyid("fruitprice").value = (3).tofixed(2); } }  <span style="font-family: calibri; font-weight: bold;">choose fruit</span>: <br> <select id="fruits" onchange="if (this.selectedindex) price();" /> <option value=""></option> <option value="apple">apple</option> <option value="orange">orange</option> </select> <input type="text" size="2" id="fruitprice" /> 

since have not provided any code, going assume following

  1. you trying via change event of drop-down
  2. you using jquery

your select markup

<select id="selectnum">     <option value="0"></option>             <option value="1">one</option>     <option value="2">two</option> </select> 

and input

<input id="txtsomething" type="text"> 

your onchange handler

$('#selectnum').on('change', function() {    $('#txtsomething').val(this.value) }) 

this should started.


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -