开发者

Kindly suggest me how to create depend Textboxes in ASP.NET

开发者 https://www.devze.com 2023-02-16 17:53 出处:网络
I have numeric 开发者_开发百科textbox1, numeric textbox2 and numeric textbox3, where textbox3 should show the value that is the multiple of textbox1 and textbox2. The textbox3 should change dynamicall

I have numeric 开发者_开发百科textbox1, numeric textbox2 and numeric textbox3, where textbox3 should show the value that is the multiple of textbox1 and textbox2. The textbox3 should change dynamically when the values in the other two change. Thanks.


<script language="javascript" type="text/javascript">
function calculate()
{
    if((document.getElementById("TextBox1").value != "") && (document.getElementById("TextBox2").value != ""))
    {
        document.getElementById("TextBox3").value = document.getElementById("TextBox1").value * document.getElementById("TextBox2").value;
    }
}
</script>

  <asp:TextBox runat="server" ID="TextBox1" onblur="calculate();"></asp:TextBox>
        <asp:TextBox runat="server" ID="TextBox2" onblur="calculate();"></asp:TextBox>
        <asp:TextBox runat="server" ID="TextBox3"></asp:TextBox>


You would need to either use javascript and do it client side, ajax and do it server side, or set the textboxes to postback automatically on change.

I'd recommend using jquery:

$('#textbox1, #textbox2').change(function() {
    $('#textbox3').val(parseFloat($('#textbox1').val()) * parseFloat($('#textbox2').val()));
});

Where #textbox1, #textbox2 and #textbox3 are the ID's of the three textboxes. (You may need to use <%= TextBox1.ClientId %> if you're using ASP.NET as the ID's are generated dynamically.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号