javascript - textbox values on change -
i have 3 textboxes same id's in table. have 1 dropdown on top of table. while changing dropdown need set textbox values same dropdown value.
i used following code , able change first textbox, others not getting values.
function myhome() { var zoneid = $("#funderids").val(); $("#funder").val($("#funderids").val()); }
<select id="funderids" name="funderids" onchange="myhome()" style="width: 25%;"> <option value="0">--select--</option> <option value="3">option1</option> <option value="5">option2</option> <option value="6">option3</option> </select> <input type="text" name="funder" id="funder" value=""> <input type="text" name="funder" id="funder" value=""> <input type="text" name="funder" id="funder" value="">
can give advise on making mistake?
it invalid use same id more 1 element, should unique throughout document, use class instead!
id's unique
- each element can have 1 id
- each page can have 1 element id
classes not unique
- you can use same class on multiple elements.
- you can use multiple classes on same element.
change code to:
function myhome() { var zoneid = $("#funderids").val(); $(".funder").val($("#funderids").val()); } <select id="funderids" name="funderids" onchange="myhome()" style="width:25%;"> <option value="0">--select--</option> <option value="3">option1</option> <option value="5">option2</option> <option value="6">option3</option> </select> <input type="text" name="funder-1" id="funder-1" class="funder" value=""> <input type="text" name="funder-2" id="funder-2" class="funder" value=""> <input type="text" name="funder-3" id="funder-3" class="funder" value="">
Comments
Post a Comment