开发者

Call multiple JavaScript functions on onblur

开发者 https://www.devze.com 2023-03-26 08:08 出处:网络
I have to get a running total from four textboxes and have that total populate in two textbox controls. I was using onblur and that was working fine to display the total in one textbox. When I call th

I have to get a running total from four textboxes and have that total populate in two textbox controls. I was using onblur and that was working fine to display the total in one textbox. When I call this JavaScript function twice on the onblur event, I get an JavaScript error. Here is my JavaScript function.

function compute(clid, val1, val2, val3, val4) {
        var entry1 = Number(document.getElementById(val1).value);
        var entry2 = Number(document.getElementById(val2).value);
        var entry3 = Number(document.getElementById(val3).value);
        var entry4 = Number(document.getElementById(val4).value);
        var grandtotal = entry1 + entry2 + entry3 + entry4;
        document.getElementById(clid).innerHTML = grandtotal;
    }

And here is the codebehind.

protected void Page_Load(object sender, EventArgs开发者_如何转开发 e)
{
    txtdlscwinter.Attributes.Add("OnBlur", "compute('" + txtdlsctotal.ClientID + "','" + txtdlscwinter.ClientID + "','" + txtdlscspring.ClientID + "','" + txtdlscsummer.ClientID + "','" + txtdlscfall.ClientID + "'); compute('" + txtSpiffDLSC.ClientID + "','" + txtdlscwinter.ClientID + "','" + txtdlscspring.ClientID + "','" + txtdlscsummer.ClientID + "','" + txtdlscfall.ClientID + "');");
}

I am calling the same function twice but passing a different ClientID. What am I doing wrong here?


You need to set value rather than innerHTML.

0

精彩评论

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