views:

46

answers:

1

I have two forms on the same page, but I want the second form to be displayed only if a certain field in the first form is greater that four. How can I achieve this using JavaScript? I'm using Django.

+2  A: 

You probably don't want to do this in Django. Expanding on T. Stone's answer, something like this jQuery should work:

<script>
$(document).ready(function(){
  $("#some-field").change(function () {
    var currentVal = parseInt($(this).val());
    if (!isNaN(currentVal) && currentVal > 4) {
      $('#form2').show();
    }
    else {
      $('#form2').hide();
    }
  })
  .change();
});
</script>

You'll want to mark form2 as hidden initially.

Dominic Rodger
This is the correct method, as I had mis-interpreted what the OP was asking for.
T. Stone
I've now added code to hide the form if the value fails the test.
Dominic Rodger
Works pretty well...thanks Dominic n T for all the help
Stephen
@47 - no problem - glad it worked!
Dominic Rodger