How to make function related to assigning comboboxes

on my html page there are three input forms that have been linked to each other. first combobox input with option:

  • TCA
  • Intasept second and third input as a text type.

if the first input pad is “TCA” when the user enters the second input “01”, therefore, “1-120” is automatically populated at the third input. if the first input fill is "intasept", when the user enters the second input "01" at the third input, "1-32" is automatically fixed.

by simple logic.

  • first entry = "TCA" (user-selected option).
  • second input = "01" (manually entered by the user).
  • third input = "1-120" (automatic input).

this will continue at intervals of 120. ex:

  • second entry: 02: 03, etc.
  • third input: 121-240: 241-360, etc.

if in the first input = Intasept (selected by the user).

  • second input = 01 (manually entered by the user).
  • third input = 1-32 (automatic input).
  • this will continue at intervals of 32.

Example:

  • second entry: 02: 03, etc.
  • third input: 32-64: 65-96, etc.

Help me how to make this function in javascript. this is what i tried but it doesn't work

var interval, step; $("#first").change(function (e) { if (this.option:selected) interval = { // map of input value attributes to 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) + "-" + ((interval * step + interval)-interval)); } 

http://jsfiddle.net/n8pSt/

+6
source share
1 answer

http://jsfiddle.net/QXFKL/5/

 if (this.option:selected) interval = { // map of input value attributes to interval values "TCA": 120, "intasept": 32 }[this.value]; 

but the value you get is "Intesept" Casesensitive

also your if did not work so i deleted it

+1
source

Source: https://habr.com/ru/post/945053/


All Articles