Answered by:
get textbox value and populate another textbox

Question
-
User1717218719 posted
Hi all
I am looking to calculate the following :
value in TextBox2 - value in TextBox3 = (populates) TextBox4 value
I would also like to validate that the numbers entered in the textboxes defaults to a decimal (.00)
Im using VB if anyone could help that would be great.
Wednesday, June 12, 2019 8:02 AM
Answers
-
User288213138 posted
Hi E.RU
You can use RegularExpressionValidator control to validate whether the value of an associated input control matches the pattern specified by a regular expression.
The code:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="Regex1" runat="server" ValidationExpression="^(([1-9]{1}\d*)|(0{1}))(\.\d{2})$" ErrorMessage="Please enter valid decimal number(00)" ControlToValidate="TextBox1" />
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 12, 2019 10:27 AM -
User288213138 posted
Hi E.RU,
You can use the num.toFixed(2) method in jquery.
The code:
<script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function () { var test = $("#TextBox1").val(); console.log(test); var num = new Number(test); console.log(num); alert(num.toFixed(2)); }); }); </script> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" />
The result:
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2019 10:26 AM
All replies
-
User1717218719 posted
I have the following code:
TextBox4.Text = Val(TextBox2.Text) - Val(TextBox3.Text)
but how do I default values to decimal?
Wednesday, June 12, 2019 8:48 AM -
User288213138 posted
Hi E.RU
You can use RegularExpressionValidator control to validate whether the value of an associated input control matches the pattern specified by a regular expression.
The code:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:RegularExpressionValidator ID="Regex1" runat="server" ValidationExpression="^(([1-9]{1}\d*)|(0{1}))(\.\d{2})$" ErrorMessage="Please enter valid decimal number(00)" ControlToValidate="TextBox1" />
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Wednesday, June 12, 2019 10:27 AM -
User1717218719 posted
This is great thaks a million!
is it possible to have it so when I type in a whole number eg. 3 it automatically corrects to 3.00 ?
Wednesday, June 12, 2019 10:30 AM -
User288213138 posted
Hi E.RU,
You can use the num.toFixed(2) method in jquery.
The code:
<script type="text/javascript"> $(document).ready(function () { $("#Button1").click(function () { var test = $("#TextBox1").val(); console.log(test); var num = new Number(test); console.log(num); alert(num.toFixed(2)); }); }); </script> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button" />
The result:
Best Regards,
Sam
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Friday, June 14, 2019 10:26 AM