Register Advertise with usHelp Desk Today's Posts Search

Closed Thread
Thread Tools Search this Thread
Unread 9th Dec 2012, 07:26 PM   #1
Digital Marketer
War Room Member
 
WillR's Avatar
 
Join Date: 2010
Location: Australia
Posts: 12,472
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
Default
How to Open Form Submit in New Window?
Share on: 
fb share twitter share gplus share more share

Hi,

I am currently using a form where there are 3 selections with radio buttons next to them. Depending on the radio button a person selects, when they submit the form they are then taken to a corresponding url. So there are 3 different urls they can be taken to depending on the selection they make before submitting the form.

The problem I am having is getting those urls they are taken to upon submitting the form, to open up in a NEW browser window. At the moment they are just forwarded to that url in the same window but that's not what I want.

Any ideas how to make this work. Here is the current code I am using.

Note: I have already tried adding the rel="nofollow" target="_blank" to the form action line but that does not work.

Code:
<script type="text/javascript">

  function doSubmit(form) {
    var urls = form['url'];
    var i = urls && urls.length;
    while (i--) {
      if (urls[i].checked) {
        window.location = urls[i].value;
      }
    }
    return false;
  }

</script>
</body>
Code:
<form action="#" onsubmit="return doSubmit(this)">
<input type="radio" name="url" class="styled" checked="checked" value="http://google.com/option1" /><br />
<input type="radio" name="url" class="styled" value="http://google.com/option2" /><br />
<input type="radio" name="url" class="styled" value="http://google.com/option3" /><br />
<input name="" type="submit" class="button2" value="Select" />
</form>

WillR is offline  
Unread 10th Dec 2012, 02:25 AM   #2
Social Apps Made Easy
War Room Member
 
FirstSocialApps's Avatar
 
Join Date: 2012
Location: Mooresville, NC
Posts: 913
Thanks: 231
Thanked 259 Times in 213 Posts
Default
Re: How to Open Form Submit in New Window?
Share on: 
fb share twitter share gplus share more share

Dont do it the way you are. Try it this way.

add rel="nofollow" target="_blank" to form

Then use JQUERY to change the forms action attr as needed

.attr() – jQuery API

FirstSocialApps is offline  
Unread 10th Dec 2012, 05:59 AM   #3
Elite Warrior
Registered Member
 
Join Date: 2012
Location: USA
Posts: 60
Thanks: 0
Thanked 3 Times in 3 Posts
Default
Re: How to Open Form Submit in New Window?
Share on: 
fb share twitter share gplus share more share

Instead of window.location, use window.open().
window.open(urls[i].value);
Rideem3 is offline  
Unread 10th Dec 2012, 09:51 AM   #4
Advanced Warrior
War Room Member
 
Brandon Tanner's Avatar
 
Join Date: 2006
Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
Default
Re: How to Open Form Submit in New Window?
Share on: 
fb share twitter share gplus share more share

There are only 2 ways to do this, and neither method is 100% reliable. Some browsers ignore rel="nofollow" target="_blank" entirely, and the Javascript method (window.open or window.location) is blocked by a lot of popup blockers, firewalls, etc. Not to mention it won't work at all for anyone who has Javascript disabled.

So the best you can do is use the Javascript method first, then for anyone who has JS disabled, put your rel="nofollow" target="blank" inside a <noscript> tag as a backup. Even if you do that, it will not work for every single visitor due to the reasons mentioned above, but it's better than just relying on a single method.


Brandon Tanner is offline  
Closed Thread


Bookmarks

Tags
form, open, submit, window


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 Off
Pingbacks are Off
Refbacks are Off




All times are GMT -6. The time now is 03:57 PM.