Re: Form submit button not working with URL redirection
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Form submit button not working with URL redirection

From: alu <none@none.com>
Date: Tue Aug 09 2005 - 04:54:01 CEST

"Hongyu" <forward@hongyu.org> wrote
> I am trying to implement a simple JavaScript of redirecting my window
> to a new URL upon clicking a submit button. This is an easy task except
> when I have to put an input type='submit' in front of the onClick
> command. It always commits the CGI action, and skip the URL redirect
> part. The example code is below
>
> <form action=mycgi.pl>
> <input type='submit' name=submit value='Submit'
> onClick="window.location.href='http://myserver.com'">
> </form>
>
> I know if "type=button" is used here, the script can work, but I have
> to use "type=submit" for some particular reasons in my project.
>
> Does anyone have a good way to circumvent this problem? Appreciate your
> time!
>
> Hongyu

>From my limited knowledge of forms, I would think that your .pl file should
be handling the redirect.
Someone correct me if I'm mistaken...
I don't think the onclick is being skipped, it's just being immediately
replaced by the action.
You can test this as below, which results in an alert "button", then an
alert "form", then the google redirect.

<form action="http://www.google.com" onsubmit="alert('form');">
 <input type='submit' name=submit value='Submit' onClick="alert('button')">
</form>

-alu
Received on Tue Oct 18 03:06:50 2005