Hi @RAVI,
How to do using javascript without postback..
It looks like you are using the TextBox control in a WebForms project, if you don't want it postback, you should set the AutoPostBack
attribute to False. Something like this:
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="false"></asp:TextBox>
And when using this control, you may be accustomed to using the Enter key to do postback, in which case you can add the following code to disable the Enter key to submit the form, and calculate the desired result using the code that community members provided:
<script src="Scripts/jquery-3.4.1.min.js"></script>
<script>
$('#form1').on('keyup keypress', function (e) {
var keyCode = e.keyCode || e.which;
if (keyCode === 13) {
e.preventDefault();
return false;
}
});
$("#TextBox1").on('keyup keypress', function (e) {
if (e.key === 'Enter' || e.keyCode === 13) {
// Do something
let t = e.target.value;
t = t.trim();
if (t.endsWith("=")) {
let v = eval(t.substring(0, t.length - 1));
$("#TextBox1").val(v);
}
}
});
</script>
Hope this can help you.
Best regards,
Xudong Peng
If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.