I understand about using toFixed(3). What I’m not sure about is not to send this to a function. I have used onkeyup or onchange before but not passing a paramater. I need to know which textbox to update with the decimal.(the one calling the function) At the moment the alert is not working. All I want to do is immediately update the number in a textbox when the input stops. If I enter 103, it needs to update to 103.000. I have passed static variables in my textbox before, but not a number. Is this different?
<asp:TextBox ID="txtmaxbal" runat="server" Style="text-align: right" Width="40" MaxLength="7" onkeyup="percent(this)"></asp:TextBox>%
<script type="text/javascript" language="javascript">
function percent(tbox) {
var retval = tbox.value.toFixed(3);
var tboxid = tbox.id;
alert(retval, id);
}
</script>
2
Answers
You have several issues:
tbox.value
is a string, so you can’t directly use.toFixed()
.alert(retval, id);
whereid
is not defined.Replace your existing
percent
function with the code above.You want to debounce the input and not update until the user stops typing or leaves the field. you do NOT want to alert since that blocks all further processing or typing on an interactive event handler like keydown/keyup/input
Here is debounced typing (adjust the timeout)
Changing and leaving