473,395 Members | 1,761 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Form submit button not working with URL redirection

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

Aug 9 '05 #1
2 12472
alu

"Hongyu" <fo*****@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
Aug 9 '05 #2
Try this code...

<form action="mycgi.pl" onsubmit="return false;">
<input type="submit" name="submit" value='Submit'
onClick="window.location.href='http://myserver.com'">
</form>

The ' onsubmit="return false;"' will prevent the form submission so
that the onclick javascript will be executed.

Hope it helps.

Binny V A

Aug 9 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Nick | last post by:
Should be a quickie but I just can't get it to work. I have a form where my users can submit their football picks, when they click submit I would like another sized window to appear...
17
by: Dave Smithz | last post by:
Hi there, A PHP application I built has a section which lists a number of members to a club whose names each appear with a check box beside them that can be ticked. These check boxes are part...
0
by: Dan Sikorsky | last post by:
We're using Remote Scripting to update counters, or colors, displaying on a web page form at a fixed interval, and the form's submit button event handler is executed without clicking the button. I...
7
by: David T. Ashley | last post by:
Hi, For a web page, I want a SUBMIT button that commits the form data and a CANCEL button that goes to a different target (i.e. a different script). I haven't figured out how to do this,...
5
by: Nerry | last post by:
Hello, i'm new to HTML I've created a registration form and have a submit button. i want that if the form is blank and submit is clicked that I could link it to a page saying, "please input...
0
by: Michel Reij | last post by:
I have created a small recorder application in dotnet that records my actions in Internet Explorer into a replayable simulation. For this I have registered the mshtml.DocumentEvents2 class. It...
10
by: k3pp0 | last post by:
Hello. Here's my example form: <form method="get" action=""> <p> <input type="radio" name="radio_example" id="radio1" value="radio1_val" /> <label for="radio1">radio button one</label> </p>
6
by: ziycon | last post by:
I hope this is the right place for this question, I'm working on a site with HTML/CSS/PHP/AJAX and i have a form that i don't want the submit button to be 'enabled' or clickable until all the other...
2
by: omar999 | last post by:
hi guys I am pulling in prices/dates from a sql server database/table on to a webpage using sql/asp/html/css. these prices/dates are then editable via a simple sql update statement on a css/div...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.