开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜