Hi,
Please replace you function
function addNumbers()
{
var val1 = parseInt(document.getElementById('value1').value);
var val2 = parseInt(document.getElementById('value2').value);
var ans = document.getElementById('answer');
ans.value = val1 + val2;
}
With the below code.
function addNumbers()
{
var val1 = parseInt(document.getElementById('value1').value);
var val2 = parseInt(document.getElementById('value2').value);
var ans = document.getElementById('answer');
if(isNaN(val1))
{
val1=0;
}
if(isNaN(val2))
{
val2=0;
}
ans.value = val1 + val2;
}
Also change the second method "addNumbers" to AddNumber2() or relevant to you naming convention.
Also check the NaN value using isNaN method of JavaScript in second function.
As you can not have the same name for two different functionalities.
And will always call the first method as you have given same name to both method.
Hope this will help you.