Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Onclick open new URL in same browser while Post Opens new Browser

Status
Not open for further replies.

photobookie

Programmer
Aug 26, 2007
2
US
I have a form whose Submit button posts to a new browser instance. I also need that same submit button to perform an onclick to refresh its page with a new url.

Something like the following doesn't work for me. What am I doing wrong?

<form method="POST" action=" target="_blank">

<input TYPE="Button" CLASS="Button" value="Continue Shopping" name="Shop" OnClick="javascript:location.href='
</form>

Thanks in advance.
 
Hi

Do not use the [tt]javascript:[/tt] pseudo-protocol in the event handler calls.
Code:
<input type="submit" class="Button" value="Continue Shopping" name="Shop" onclick="location.href='[URL unfurl="true"]http://www.mysite.com';">[/URL]

Feherke.
 
Thanks feherke, however this is still not working for me. Now it goes to the URL listed in the onclick, but the post doesn't submit the form.

What javascript needs to be in the header in order to make this work?

<form method="POST" action=" target="_blank">

<input TYPE="SUBMIT" value="Go to Amazon" name="submit" OnClick="location.href=' style="width=150px; font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif">

</form>
 
Hi

Hmm... Then this :
Code:
<input type="submit" value="Go to Amazon" name="submit" onclick="[red]setTimeout('[/red]location.href=[red]\[/red]'[URL unfurl="true"]http://www.mysite.html[/URL][red]\[/red]'[red]',500)[/red]" style="width=150px; font-size:11px; font-family:Verdana, Arial, Helvetica, sans-serif">

Feherke.
 
[1] Avoid naming submit button "submit". Not that it necessarily break the functionality, it may when conditions met.
><input TYPE="SUBMIT" value="Go to Amazon" name="submit"
[tt]<input TYPE="SUBMIT" value="Go to Amazon" name="[red]namedotherthan[/red]submit" [/tt]
[2] I won't repeat feherke's good advice. I tend to concur.
[3] Nevertheless, if there are onclick handler (bubbled) or others on the form or parent container(s) of the button itself, in particular, interactive ones, unpredictable behaviour _might_, all the same, result and break the functionality or exhibit browser-dependent behaviour. That may be rare occasion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top