Reputation: 71
var totalEnteredCount = 0;
function totalEntered(field){
if(field.value != '')
{
totalEnteredCount++;
}
alert(Count);
if(totalEnteredCount == 3)
{
var IV = document.getElementById("IVUnit").value;
var FV = document.getElementById("FVUnit").value;
var Distance = document.getElementById("DUnit").value;
var Acceleration = document.getElementById("AUnit").value;
var Time = document.getElementById("TUnit").value;
}
}
This function is called onBlur from HTML, every time a textbox either has data entered or not. If data is entered, I want it to increment the totalEnteredCount by 1. However the global variable is undefined. Is there a way to track how many times the function is called?
HTML is below:
<td>Initial Velocity: </td>
<td> <input type = "textbox" name ="InitVelocityInput" onKeyPress="return isAcceptable(event)" onBlur = "totalEntered(this)" id = "IVUnit"> </td>
Upvotes: 2
Views: 72
Reputation: 1909
Corrected code-
var totalEnteredCount = 0;
function totalEntered(field)
{
if(field.value !== '') //using !== instead of != for string comparision
{
totalEnteredCount++;
}
alert(totalEnteredCount); //using totalEnteredCount instead of Count
if(totalEnteredCount == 3)
{
var IV = document.getElementById("IVUnit").value;
var FV = document.getElementById("FVUnit").value;
var Distance = document.getElementById("DUnit").value;
var Acceleration = document.getElementById("AUnit").value;
var Time = document.getElementById("TUnit").value;
}
}
JS Bin: http://jsbin.com/xujugebeva/edit?html,js,output
Upvotes: 1
Reputation: 12025
You're trying to alert "Count" which is undefined: alert(Count);
This cause a runtime error and prevent the rest of the code from executing. Try to comment-out this line
Upvotes: 1