Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm having two textboxes Textbox1 and Texbox2 and onkeyup event i'm adding +1 in Textbox1's Value. and Printing it In Textbox2 But if i blank textbox1's value then in Textbox2,showing NaN.
i want to remove NaN. can anybody give suggestions about it?Thanks in Advance.
Posted
Comments
KM Perumal 7-May-13 9:01am    
Show ur script
Surendra0x2 7-May-13 9:24am    
function addyear()
{

var yr=parseInt(document.getElementById("<%=TextBox1.ClientID %>").value);

document.getElementById("<%=TextBox2.ClientID %>").value=yr+1;



}

NaN (not a number) is showing up because in this case you are trying to add numeric and non-numeric (blank) values.

in javascript code where you are adding up, just check the text box value and do the addition only if it is not blank.

hope this helps
 
Share this answer
 
Comments
CPallini 7-May-13 9:09am    
simplex et unum: 5.
Thanks7872 7-May-13 11:37am    
upvoted.!
Use function isNaN( number );

See example of my function

function CheckInt( num, min, max ){
if( isNaN( num ) ){
return false;
}else{
num = parseInt( num );
return min <= num && num <= max;
}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900