[thelist] A little JS Problem

Brian Cummiskey Brian at hondaswap.com
Wed Dec 29 22:29:54 CST 2004


Sorry about my last blank message-  hit send by accident before i even 
typed anything  :X

Norman Bunn wrote:

>   I have tried to get this to work, but I can't seem to get the JS to 
> override the ACTION in the FORM tag.  What am I missing?
>
> The HTML:
>
> <FORM METHOD=GET ACTION="cpa.html" NAME="cpaform" onSubmit="return 
> cpaPass();">

the easiest way to do this is to simply remove the action from the form 
all together, and let javascript handel the action.

<form action="" name="cpaform" onsubmit="cpaPass();">  <!-- note, the 
lack of return- as we aren't returnning anything from the function 
anymore -->

and change this:

> if(alertFlag == 1) {      alert('The password you entered is 
> invalid.\nPlease re-enter your SCACPA password.');      return false; 
>   }   else {
>   return true;
>   }
> }

to:

 if (alertFlag == 1 // the alert/return flase here.............
else {
    document.cpaform.action="cpa.html";
    document.cpaform.method="get";
    document.cpaform.submit();
}

The only problem with this method is that if the user has javascript 
turned off, nothing happens when the submit button is pressed.

But the again, the way you have the code now, if javascript is off, they 
will simply be directed to cpa.html without any kind of validation 
whatsoever.

If you want ANY kind of security at all, server-side is the only real 
means to do it and have it hold any real value (asp/php/jsp/cfm/cgi/etc...)


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.298 / Virus Database: 265.6.6 - Release Date: 12/28/2004



More information about the thelist mailing list