Reputation: 221
I am not good at JS or jQuery. I take the follow code for better explaining what I what. When a user input 400 or more to triglycerides, the LDL is autopopulated with 'N/A'. How do I implement JS or jQuery to do that? Thanks
<form>
<input name='triglycerides" value="" />
<input name='LDL' value="" />
</form>
My actual code is as follows:
$('#ldl_override').keyup(function(){
var val = parseInt($(this).val());
if(val > 399)
$('#qIn726').val('N/A');
});
elseif($ldl_override && $questionID == 728)
{
$question .= "<input $maxLengthString id=\"ldl_override\" name=\"field[" . $questionID . "]\" type=\"text\" value=\"" . htmlspecialchars($answer) . "\" />\n";
}
Upvotes: 0
Views: 2335
Reputation: 230
$('input[name="triglycerides"]').change(function() {
var val = parseInt($(this).val());
if(val > 399) {
$('#LDL').val('N/A')
}
});
Upvotes: 0
Reputation: 12437
Use id
to select with #
! For example:
HTML:
<form>
<input id="triglycerides" value="" />
<input id="triglycerides-result" value="" disabled="disabled" />
</form>
JQuery:
$('#triglycerides').keyup(function(){
var val = parseInt($(this).val());
if (val > 399)
$('#triglycerides-result').val('high');
else
$('#triglycerides-result').val('normal');
});
See JsFiddle
Upvotes: 0
Reputation: 13756
You can do it easily with jQuery
$('input[name="triglycerides"]').keyup(function(){
var val = parseInt($(this).val());
if(val > 399)
$('input[name="LDL"]').val('N/A');
});
Upvotes: 1
Reputation: 16091
with jquery:
<form>
<input name="triglycerides" value="" onChange="javascript: if($('#triglycerides').val() > 400) $('#LDL').val('N/A'); />
<input id="LDL" name='LDL' value="" />
</form>
Upvotes: 1