I have a simple function I need to repeat 3 times for 3 seperate controls. It seems silly to replicate the same function 3 times however I don't myself know how to do this.
<script type="text/javascript">
$(document).ready(function () {
// $("#LeaveHoursTextBox").blur(function () {
$("input[type=text][id*=LeaveHoursTextBox]").blur(function () {
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>
The above code works when leaving the first text box. Instead of copying and pasting for the other 2 text boxes how would I add them into this same code element ?
var num1 = parseInt(document.getElementById("LeaveHoursTextBox").value)tovar num1 = parseInt($("#LeaveHoursTextBox").val()). Its shorter and I personally think that it is easier to read.