By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,940 Members | 1,300 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,940 IT Pros & Developers. It's quick & easy.

Removal of "undefined" keyword from the textbox

P: 92
hello guys,
I am having mulitple textboxes, where numerals are fed and onBlur of each text box, the value gets added and is displayed in a text box at bottom. The total field is made readonly since we dont want the users to enter false values.

Now, if i enter a values in each text box it adds up dynamicaly and i can view the result/total in the readonly field.

Also if i delete the values in each text box the total gets decremented automatically, the problem here is when is delete all the values the total field will be automatically set to "Un-Defined". I need to get rid of this keyword since i dont want these type of values storing in the DB.

Your help would be much appreciated. Thanks in advance.
Oct 19 '09 #1
Share this Question
Share on Google+
6 Replies


hsriat
Expert 100+
P: 1,654
Do some validation before you add the number. Use parseInt().
Oct 19 '09 #2

P: 92
See my code below:

c = new Number(Remove_Comma(document.frm.txt_1.value));
d = new Number(Remove_Comma(document.frm.txt_2.value));
e = new Number(Remove_Comma(document.frm.txt_3.value));

var Calc = c + d + e

document.frm.Total.value=roundNumber(Calc,2)

So while i enter the values in textbox a, b and c it automaically calculates and stores the result in total field.
Similarly, if i delete the values in each field the total values gets decremented anfd finally when all the values are deleted the total field sets to "Un-defined", which i dont to see, rather it should be 0. Please help
Oct 19 '09 #3

RamananKalirajan
100+
P: 607
Just before adding all the three variables c, d and e.. Check wether its null

Expand|Select|Wrap|Line Numbers
  1. if(c==null||c==""||c=="null")
  2. {
  3.    c=0;
  4. }
like this do for all the three variables your problem will be solved.

Thanks and Regards
Ramanan Kalirajan
Oct 20 '09 #4

Dormilich
Expert Mod 5K+
P: 8,639
@RamananKalirajan
wouldnít
Expand|Select|Wrap|Line Numbers
  1. c = c || 0;
do the same? (except for "null", which is a string)
Oct 20 '09 #5

ivosilva
P: 17
Hello, chandhseke.

You could use isNaN to check if the value is a number. If not, then set to 0.

Best regards!
Oct 20 '09 #6

P: 92
Hi Folks,

Many thanks for posting your reply. My problem got resolved!!. It is working fine now.

Best Regards!
Oct 20 '09 #7

Post your reply

Sign in to post your reply or Sign up for a free account.