Sorry to ask such a basic question. Say, I have two inputs. The first one is always visible, while the second shows up only when the first one’s value is less than 0. I tried to use .change to implement this activity, however it does not work. So can anyone give me some suggestions?
Thanks in advance.
HTML code:
<table>
<tr><th><label for="id_first">First input:</label></th><td><input type="text" name="First input" id="id_first" /></td></tr>
<tr><th><label for="id_second">Second input:</label></th><td><input type="text" name="First input" id="id_second" />
</td>
</tr>
</table>
jQuery code
<script type="text/javascript" src=" ../stylesheets/jQuery-1.7.2.js"></script>
<script>
$(document).ready(function() {
$('#id_second').closest('tr').hide();
$('#id_first').change(function() {
if ($(this).val() <0){
$('#id_second').show()}
else{
}
});
your jquery code should be as below. You had a syntax error. You did not close the change function, and you have to show “tr”, not just the input element