php - how to populate the textbox value on the selection of a combo box -
i have form has 1 combo box , 3 textboxes. 3 textboxes meant calculation purpose. first textbox amount, second 1 received , last 1 read shows balance , combo has values - full, part , none. if user selects full the received textbox should become read , amount entered in amount textbox should come in the received textbox. if user selects part textbox should available user enter amount. if user selects none balance textbox should populated value entered in amount textbox.
<select id="pay" name="pay" tabindex="12"> <option value=""></option> <option value="1">full</option> <option value="2">part</option> <option value="3">none</option> </select> <input type="text" id="amt" name="amt" value="" size ="8" onblur="calculatetext()" style="background-color:transparent; color:blue; text-align:right" tabindex="17"/> <input type="text" id="resc" name="resc" value="" disabled="disabled" size ="8" onblur="calculatetext()" tabindex="18"/> <input type="text" id="bal" name="bal" readonly="readonly" value="" size ="8" onblur="calculatetext()" tabindex="19"/>
added jsfiddle: http://jsfiddle.net/mackieee/fjxzy/1/
here's started. more or less you've asked, there usability issues because haven't said in every case, limited set of cases. i'll leave working want.
<script> function calculatetext(el) { var form = el.form; var idx = form.pay.selectedindex; if (idx <= 0) { form.reset(); return; } if (form.pay.value == 1) { form.resc.disabled = true; form.resc.value = form.amt.value; form.bal.value = 0; } else if (form.pay.value == 2) { form.resc.disabled = false; form.bal.value = form.amt.value - form.resc.value; } else if (form.pay.value == 3) { form.resc.disabled = true; form.resc.value = 0; form.bal.value = form.amt.value; } } </script> <form> <select name="pay" onchange="calculatetext(this);"> <option selected>please select option</option> <option value="1">full <option value="2">part <option value="3">none </select><br> amount: <input name="amt" onblur="calculatetext(this)"><br> received: <input name="resc" disabled onblur="calculatetext(this)"><br> balance: <input name="bal" readonly><br> <input type="reset"> </form>
Comments
Post a Comment