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
2010-01-08 09:41:51
This is the correct method, as I had mis-interpreted what the OP was asking for.
T. Stone
2010-01-08 09:45:09
I've now added code to hide the form if the value fails the test.
Dominic Rodger
2010-01-08 09:49:15
Works pretty well...thanks Dominic n T for all the help
Stephen
2010-01-08 10:01:09
@47 - no problem - glad it worked!
Dominic Rodger
2010-01-08 10:01:26