There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
URL redirect when submit button is clicked


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
ebay258's Avatar
Account Disabled with 37 posts.
 
Join Date: Dec 2004
Experience: Intermediate
20-Jan-2005, 11:27 AM #1
Question URL redirect when submit button is clicked
Hello,
I'm trying to make the submit button on my email form redirect to a different URL when it's clicked and still submit the message. What's the code to do this and where do I put it? THE FORM IS IN HTML
Shadow2531's Avatar
Distinguished Member with 2,629 posts.
 
Join Date: Apr 2001
21-Jan-2005, 04:17 AM #2
If you truly want to submit to one page and redirect to another, you are not going to like your options. The page you are submitting to should do the redirection.

However, you have 3 options if you only have html and javascript.

Submit to the one page in a new window and then change the location of the current window.

You do have to consider popup blockers, but if you are actually clicking to submit, the popup blocker should let it through unless the person has "block all popups" set for their browser.

The good thing about that way is the redirection doesn't interfere with the submission. You could autoclose the popup window after a certain time, but if it's closed too soon, it could interupt the tranfer.

Now the another way is to have an invisible iframe that you submit to. You use javascript for this to disable the normal form actions, submit to the iframe and then change the location after a certain amount of time.

That method will work, but the change of location can interupt the submission in the iframe.

The 3rd way and maybe the best way is to use the XML HTTP Request Object.

I've really never messed with it so you'll have to investigate that to see if it allows you do to what you want. It won't be supported in old browsers so if you have to support ancient browsers, this is not the way to go. The url I posted should definitely help. If you click the "loadcode button on that page, you'll set how it works and how you can use get or post to submit to the server.

Here's an example of the iframe way though that will give you some hints of how to control the forms. (tested only in opera). When you click submit, it will do a google search in the hidden iframe and then in 3 seconds, redirect you to www.hardocp.com.

Code:
<script type="text/javascript">
    function multi() {
        var obj = document.forms.searchform;
        var info = obj.action + "?" + obj.q.name + "=" + obj.q.value;
        frames['hide'].location = info;
        setTimeout("location = 'http://www.hardocp.com';", 3000);
    }
</script>
<form id="searchform" action="http://www.google.com/search" method="get" onsubmit="return false;">
    <div>
        <label for="search">Search Google</label>
        <input id="search" type="text" name="q" />
        <a href="javascript:multi()">Submit</a>
    </div>
</form>
<div style="visibility: hidden; width: 0px; height: 0px;">
    <iframe name="hide" src=""></iframe>
</div>
You'll have to change things to work for the pages you need to work with.

Edit:

I tried the request object method and it works, but in Opera at least, the get request uri must be on the same domain that the script is running. That means it will work, but not if the page you are submitting to is on a different domain.
__________________
10 ? "a line as the unending horizon"
20 ? "a curve as the rolling hillside"
30 ? "a point as a distant bird"
40 ? "a ray as the rising sun"
run

Last edited by Shadow2531 : 21-Jan-2005 04:55 AM.
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:59 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.