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
3 Answers
Reset to default 3Javascript 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
版权声明:本文标题:javascript - On BLUR not firing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744681266a2619423.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论