[Javascript] Integer and String
Flavio Gomes
flavio at economisa.com.br
Tue Apr 27 13:25:06 CDT 2004
Sure!
Seems even faster than Hakan's.
Thanks
----- Original Message -----
From: "Paul Novitski" <paul at novitskisoftware.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Monday, April 26, 2004 2:26 PM
Subject: Re: [Javascript] Integer and String
> Flavio,
>
> It seems to me that you're causing yourself an unnecessary problem by
> mixing strings & integers. Why not simply initialize focus_id to -1 and
> test if(focus_id < 0) ?
>
> Paul
>
>
> At 07:12 AM 4/26/2004, Flavio Gomes wrote:
> >People, I'd like an opnion about the loop I created:
> >
> >I pass "form" (an actual form object) as an argument to a function that
> >loops over this form's inputs and validates them:
> >
> >
> >//=============================
> >function validateForm(objForm)
> >{
> > error_message = "";
> > focus_id = "";
> >
> > for (x = 0; objForm[x]; x++)
> > {
> > name = (objForm[x].name)?objForm[x].name:"";
> > switch (name)
> > {
> > case "id_number":
> > if(!objForm[x].value) //if value wasnt informed
> > {
> > error_message += "* \"ID Number\" must be informed\n";
> > if(!focus_id) { focus_id = x; } //if "focus_id" isnt set, then
> > store it
> > }
> > break;
> >
> > case "member_name":
> > if(!objForm[x].value) //if value wasnt informed
> > {
> > error_message += "* \"Member Name\" must be informed\n";
> > if(!focus_id) { focus_id = x; } //if "focus_id" isnt set, then
> > store it
> > }
> > break;
> > }
> > }
> >
> > if(error_message != "")
> > {
> > alert(error_message);
> > objForm[focus_id].focus(); //Focus the input whose focus_id was
stored
> > return false;
> > }
> >}
> >//=============================
> >
> >
> >
> >Now you ask me: "Ok, and what's the problem":
> >
> > In the line where I commented "if(!focus_id) { focus_id = x; }" the
"x"
> > for "id_number" is "0" and even if I store it, on the next check
> > "if(!focus_id)" it returns true and set the "focus_id" to the next
input...
> > The nearest to solution that I found was this:
"if(focus_id.toString()
> > != parseInt(focus_id));", and that's what I'd like to hear suggestions
on.
> >
> >Thanks in advance,
> >
> >--
> >Flavio Gomes
> ><mailto:flavio at economisa.com.br>flavio at economisa.com.br
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
More information about the Javascript
mailing list