Claudio Delgado
Claudio Delgado

Reputation: 2349

Show different parts of form depending on quantity entered in field in jQuery

              if ($('#quantity').val >= 1) {
        $( "<p>Option #1</p>" ).appendTo( "#options" );
                   $('#optionone').show();
        }
              if ($('#quantity').val >= 2) {
        $( "<p>Option #2</p>" ).appendTo( "#options" );
                   $('#optiontwo').show();        
        }

quantity is the id of a text field that gets submitted in my code. the above code should have worked (or so I thought) to display different texts for different values in the field but for some reason it just doesn't do anything.

Although this does work perfectly:

$( "<p>Option #1</p>" ).appendTo( "#options" );
$('#optionone').show();
$( "<p>Option #2</p>" ).appendTo( "#options" );
$('#optiontwo').show(); 

So obviously my condition code is wrong, but how else can I access the field value and do stuff according to the value of it?

Please help me out on this.

Thanks

Upvotes: 0

Views: 41

Answers (1)

GluePear
GluePear

Reputation: 7735

You should be using

$('#quantity').val()

instead of

$('#quantity').val

See jQuery documentation.

Upvotes: 2

Related Questions