Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Strange missing ; error , can't work it out 1

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hello,

can someone tell me what's wrong with this code please...

Code:
    // loan amount
    if(frm.loanamount.value == ""){
        msg += "Loan Amount missing.\n";   
    }
    else if(isNaN(eval(frm.loanamount.value))){
        msg += "Invalid Loan Amount.\n";
    }

I get the following error...
Error: missing ; before statement
Source File: myscript.js
Line: 585, Column: 7
Source Code:
520,000.00

in FF it seems to point to the decimal place in the number.

basically i'm checking that the form field once evaluated into a number is not NaN and the form contains the value show above.

Why is this erroring , what's the problem???

thanks,
1DMF

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
I've just tried the following ..
Code:
        else{
            var myval = eval(frm.loanamount.value);
            if(isNaN(myval)){msg += "Invalid Loan Amount.\n";}
        }
but get the same error on the eval command.

if I don't use the eval, it errors as if the value is = isNaN but it isn't , ??? what is going on ???

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
1DMF, since we have no clue what the content of the loanamount element is, there's no way for us to tell you why it's causing an error. When you eval something, you're essentially making it a part of your code - so in this instance it's like a part of your code that you're not showing us, which makes it difficult to debug.

I'm curious why you're using the eval command for this anyway. Eval has very limited uses, and from what I can see that you're trying to attempt, this is not one of them. Is this not something that a parseInt or parseFloat would not just as easily accomplish? Are we expecting loanamount to be a dollar value? There's many ways to do that other than using eval (parseFloat is usually my first choice, regexp a close second).

Also, when you get a "; expected" error, my experience has been that it's usually caused on a line nearby the error, and not on the line reported. However, since I rarely use eval, if it is the culprit I can't blindly debug from experience like I could for some other things.

Can you post a little more of the function and give an example of what kind of values are in the loanamount element, or better yet - a link to the page?

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
I showed you what the value of the input field was 520,000.00

and that was all the function code , but you are right the eval is the wrong usage I thought it turned styring vars to numbers, I was wrong.

I'm using parseDecimal instead, works fine.

sorry for the stupid question, it is getting late!

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
oh and before you ask....
Code:
// Formatting routines
function stripNonDecimal(value) {
   return value.replace(/[^0-9.]/g, "");
}

function parseDecimal(value) {
  return parseFloat(stripNonDecimal(value));
}

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Sorry, I overlooked the 520,000.00 part of the function. Glad you got it working. (and yes, I was gonna ask about the comma - I think you're beginning to know me too well, lol)

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
lol - how long has it been now, gotta be a few years at least!!!!

here is the final code, I do wonder about myself sometimes, how can i spend days writing a major complex system and then have a mental block over something so trivial - lol.

Code:
    // loan amount
    if(frm.loanamount.value == ""){
        msg += "Loan Amount missing.\n";   
    }
    else if(isNaN(parseDecimal(frm.loanamount.value))){
        msg += "Invalid Loan Amount.\n";
    }

"In complete darkness we are all the same, only our knowledge and wisdom separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top