admin管理员组

文章数量:1389772

Recently changing from writing small vb apps to web apps. Haven't switched over to C# at this time.

Trying to get an ASP Form to add a couple text boxes and show the results in another text box.

This is on and ASP.NET 4.0 form using the FormView Control in insert mode. The issue is that no matter if I click in the box, Tab into the box or out it doesn't ever seem to fire the JavaScript

<script language="javascript" type="text/javascript">
function SumCalc() 
{
    Window.alert("On Blur");
    var num1 = parseInt(document.getElementById("LeaveHoursTextBox").value);
    var num2 = parseInt(document.getElementById("LeaveHours2TextBox").value);
    var num3 = parseInt(document.getElementById("LeaveHours3TextBox").value);
    var TotalTime = num1 + num2 + num3

    document.getElementById("HoursTextBox").value = TotalTime;
}
</script>

Below is part of my html. Long page so I didn't post the whole of it..

<asp:TextBox ID="LeaveHoursTextBox" runat="server" 
Text='<%# Bind("LeaveHours") %>' 
onblur = "return sumCalc()"/>

Recently changing from writing small vb apps to web apps. Haven't switched over to C# at this time.

Trying to get an ASP Form to add a couple text boxes and show the results in another text box.

This is on and ASP.NET 4.0 form using the FormView Control in insert mode. The issue is that no matter if I click in the box, Tab into the box or out it doesn't ever seem to fire the JavaScript

<script language="javascript" type="text/javascript">
function SumCalc() 
{
    Window.alert("On Blur");
    var num1 = parseInt(document.getElementById("LeaveHoursTextBox").value);
    var num2 = parseInt(document.getElementById("LeaveHours2TextBox").value);
    var num3 = parseInt(document.getElementById("LeaveHours3TextBox").value);
    var TotalTime = num1 + num2 + num3

    document.getElementById("HoursTextBox").value = TotalTime;
}
</script>

Below is part of my html. Long page so I didn't post the whole of it..

<asp:TextBox ID="LeaveHoursTextBox" runat="server" 
Text='<%# Bind("LeaveHours") %>' 
onblur = "return sumCalc()"/>
Share Improve this question edited Oct 25, 2012 at 13:17 Alex K. 176k32 gold badges274 silver badges296 bronze badges asked Oct 25, 2012 at 13:15 dibblmdibblm 577 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

Javascript is case sensitive. Change your call to return SumCalc(), also Window.alert won't work, use window.alert or just alert instead.

Further remove the spaces from onblur = "return sumCalc()", valid html would be onblur="return sumCalc()".

There are two issue,

One

Change onblur = "return sumCalc()" to onblur = "return SumCalc()"/>

There is a typo with the JS function you calling.

Two

Change Window.alert("On Blur"); to alert("On Blur");

Bind it via jQuery blur: http://api.jquery./blur/

You can do like this:

$("#LeaveHoursTextBox").blur(function(){
    Window.alert("On Blur");
    var num1 = parseInt(document.getElementById("LeaveHoursTextBox").value);
    var num2 = parseInt(document.getElementById("LeaveHours2TextBox").value);
    var num3 = parseInt(document.getElementById("LeaveHours3TextBox").value);
    var TotalTime = num1 + num2 + num3

    document.getElementById("HoursTextBox").value = TotalTime;
})

本文标签: javascriptOn BLUR not firingStack Overflow