如何通过javascript更改值后按钮上的文本框值 [英] How to call textbox value on button click after value change by javascript
问题描述
我正在使用以下Javascript进行挂起的ammount计算,并调用payammount文本框
< asp:TextBox ID =txtpayAmmountrunat = serverMaxLength =7onfocus =myFunction1()onfocusout =myFunction()>
但是当我点击点击事件的更新按钮时updatebtn pending ammount文本框提供了私有的价值。
但实际上它应该是文本框中的新值
hi , I am using following Javascript for pending ammount calculation, and call on payammount text box on
<asp:TextBox ID="txtpayAmmount" runat="server" MaxLength="7" onfocus="myFunction1()" onfocusout="myFunction()">
but When I click on update button on click event of updatebtn pending ammount textbox gives privious value.
but actually it should be new value which is present in textbox
<script language="javascript" type="text/javascript">
var i = parseInt("1");
var t4;
var t5;
var c1 = 0;
function myFunction() {
// Created By Amol
var t1 = document.getElementById('<%= txtPendingAmmount.ClientID %>').value;
var t2 = document.getElementById('<%= TxtTotalAmmount.ClientID %>').value;
var t3 = document.getElementById('<%= txtpayAmmount.ClientID %>').value;
// Check if value pay ammount is not greater than pending Ammount
if (parseInt(t3) > parseInt(t1)) {
alert("invalid Ammount"); document.getElementById('<%= txtpayAmmount.ClientID %>').value = t1;
document.getElementById('<%= txtPendingAmmount.ClientID %>').value = c1;
}
else {
var t9 = t1 - t3;
//var t10 = t2 - t3;
document.getElementById('<%= txtPendingAmmount.ClientID %>').value = t9;
}
}
function myFunction1() {
if (i === 1) {
t4 = document.getElementById('<%= txtPendingAmmount.ClientID %>').value;
}
if (i > 1) {
document.getElementById('<%= txtPendingAmmount.ClientID %>').value = t4;
}
i = i + 1;
}
</script>
请告诉我紧急................
提前感谢...
please tell me urgent ................
thanks in advance...
推荐答案
我用一个简单的例子检查你的场景,使用如下的jQuery: -
I checked your scenario with a simple example using jQuery as below:-
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script>
// on focus out
function myFunction() {
(' #txtpayAmmount')。val( 3 );
}
// 焦点
< span class =code-keyword> function myFunction1(){
('#txtpayAmmount').val(3); } // on focus function myFunction1() {
(' #txtpayAmmount')。val( 2 );
}
< / 脚本 >
< / head >
< body >
< 表单 id = form1 runat = server >
< div>
< asp:textbox id = txtpayAmmount runat = server maxlength = 7 < span class =code-attribute> onfocus = myFunction1() onfocusout = myFunction() text = 1 xmlns:asp = #unknown > < / asp:textbox >
< asp:按钮 id = btnTest runat = 服务器 text = 测试 onclick = btnTest_Click xmlns:asp = #unknown / >
< / div < span class =code-keyword>>
< / form >
< / body >
< / html >
('#txtpayAmmount').val(2); } </script> </head> <body> <form id="form1" runat="server"> <div> <asp:textbox id="txtpayAmmount" runat="server" maxlength="7" onfocus="myFunction1()" onfocusout="myFunction()" text="1" xmlns:asp="#unknown"></asp:textbox> <asp:button id="btnTest" runat="server" text="Test" onclick="btnTest_Click" xmlns:asp="#unknown" /> </div> </form> </body> </html>
服务器端按钮点击事件处理ri得到了文本框的值,这个文本框是在聚焦上设置的,即3.
希望这对你有所帮助。
On server side button click event handler i got the value for the textbox which ever is set onfocusout i.e 3.
Hope this will be of help to you.
这篇关于如何通过javascript更改值后按钮上的文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!