javascript - Change the value of input fields, according to what is selected from the Dropdown box -


i want form input values change automatically according selected drop down box. have form 3 fields, , <select> tag has 2 <option> tags, of on same page, want values of fields inside form update dynamically different option selected on select box.

<select>   <option>cake</option>   <option>brownie</option> </select>  <form>   <input type="text" name="one"></input>   <input type="text" name="two"></input>   <input type="text" name="three"></input> </form> 

basically textboxes shoul have same words of selected option, example if 'cake' selected want textboxes display word cake, , if 'brownie' selected textboxes display brownie , forth. thanks

simple javascript solution html you've provided:

var select = document.getelementsbytagname('select')[0];  select.addeventlistener('change', function () {      var texts = document.getelementsbytagname('input');      (var = 0; < texts.length; i++)       texts[i].value = select.value;  });
<select>      <option>cake</option>      <option>brownie</option>  </select>  <form>      <input type="text" name="one"/>      <input type="text" name="two"/>      <input type="text" name="three"/>  </form>


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -