-4

Here is the structure and data of my price

if number is between 0 and 2000 (or in other word the number is less then 2000) - then must appear tax "20" if number is between 2001 and 5000 - then must appear tax 35

Price:<input type=text name=price><br>
Tax: <input type=text name=tax>
Jason Evans
  • 28,906
  • 14
  • 90
  • 154

2 Answers2

1

First you should add labels for your inputs, they are linked to the input with ids

<label for="priceInput">Price:</label><input id="priceInput" type=text name=price><br>
<label for="taxInput">Tax:</label><input id="taxInput" type=text name=tax>

And in your jquery:

//Function is executed when the priceInput is changed, so when you enter a value
$("#priceInput").change(function(){
    //Test if the value of the input is < 2000 and >0
    if (($( "#priceInput" ).val()<2000) && ($("#priceInput").val()>0)) {
        //Set the value of the tax input to 20
        $("#taxInput").val(20)
    }
    //test if tyhe value is >2000 and <5000
    else if(($( "#priceInput" ).val()<5000) && ($("#priceInput").val()>2000)){
        $("#taxInput").val(35)
    }
    else{
        $("#taxInput").val("")
    }
});

JSFiddle link

Tifa
  • 314
  • 2
  • 16
0
function setPrice()
{ 
    if ($('[name=price]').val() < 2000)
    {
        $('[name=tax]').val(20);
    }
    else
    {
        $('[name=tax]').val(35);
    }
}
Regent
  • 5,142
  • 3
  • 21
  • 35
deadulya
  • 686
  • 6
  • 15