html - How to make function on related form in javascript -
in html page there 3 form input has been relataed each other. first input combobox option:
- tca
- intasept second , third input text type.
if first input fill "tca" when user input in second input "01" in third input automaticly filled "1-120". if first input fill "intasept" when user input in second input "01" in third input automaticly fille "1-32".
on simple logic.
- first input = "tca" (selected option user).
- second input = "01" (manually input user).
- third input = "1-120" (automaticly input).
this continue interval 120. ex:
- second input: 02: 03 , on.
- third input : 121-240: 241-360 , on.
if in first input = intasept (selected option user).
- second input = 01 (manually input user).
- third input = 1-32 (automaticly input).
- this continue interval 32.
ex:
- second input : 02: 03 , on.
- third input : 32-64: 65-96 , on. me how make function in javascript.
using jquery, simple script it:
jquery(function($) { var interval, step; $("input[name=firstcombobox]").change(function(e) { if (this.checked) interval = { // map of input value attributes interval values "tca": 120, "intasept": 32 }[this.value]; update(); }); $("#secondinput").on("change keyup input paste", function(e) { step = parseint(this.value, 10); update(); }); function update() { if (isnan(interval) || isnan(step)) return; $("#thirdinput").val((interval*step+1)+"-"+(interval*step+interval)); } });
you might not use jquery else wait domready , attaching events, , might need adapt actual dom structure (input names/ids), should give idea how should done.
Comments
Post a Comment