Welcome Guest, Not a member yet? Register   Sign In
getElemntbyid returns undefined value
#8

(08-27-2018, 10:52 PM)kvanaraj Wrote: I tried but first row only affected.
echo '<td><input type="number" id="primaryincome" class="form-control" placeholder="0"> </td>';
<script type="text/javascript">
$("#primaryincome").click(function () {
    var primaryincome = $("#primaryincome").val();
   // var otherincome = $("#otherincome").val();
    var totalincome = parseInt(primaryincome) + parseInt(primaryincome);
    alert(totalincome);
    $("#totalamountremaining").val(totalincome);
})
</script>

Once you clicked the #primaryincome textbox (I assume it's a textbox because of the [type="number"]), it executes the code immediately. And since no default value was entered (but I'm suspecting that you mean [value="0"] instead of [placeholder="0"]), it will give you an invalid result.

I think your target is to when a user changes the value in your textbox, the code will be executed.
If that's what you want, you need to use $('#primaryincome').change() instead of $().click()
Reply


Messages In This Thread
RE: getElemntbyid returns undefined value - by kaitenz - 08-28-2018, 04:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB