| | #1 |
| Digital Marketer War Room Member Join Date: 2010 Location: Australia
Posts: 12,472
Thanks: 1,984
Thanked 8,187 Times in 4,079 Posts
|
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> |
| | |
| |
| | #2 |
| Social Apps Made Easy War Room Member Join Date: 2012 Location: Mooresville, NC
Posts: 913
Thanks: 231
Thanked 259 Times in 213 Posts
|
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 |
| | |
| |
| | #3 |
| Elite Warrior Registered Member Join Date: 2012 Location: USA
Posts: 60
Thanks: 0
Thanked 3 Times in 3 Posts
|
Instead of window.location, use window.open(). window.open(urls[i].value); |
| |
| | #4 |
| Advanced Warrior War Room Member Join Date: 2006 Location: USA
Posts: 1,907
Thanks: 236
Thanked 1,377 Times in 676 Posts
|
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. |
| | |
| |
|
| Bookmarks |
| Tags |
| form, open, submit, window |
| |