Link to home
Start Free TrialLog in
Avatar of markm5i
markm5i

asked on

Javascript submission of form with redirect

Should be a fairly easy question, but cannot find anything to work!

I have a simple form on an ASP page that submits to itself with a submit button. Once posted, the ASP code collects the posted data, saves to a DB and then redirects to the next page.

I would also like to place another button on the page that once clicked - will submit the form and then redirect to another page. (a save and logout button)

I figure the only way to do this would be with javascript i.e. javascript: document.forms.formname.submit(); window.location = 'page.asp'; but this is not working...any ideas?
ASKER CERTIFIED SOLUTION
Avatar of nkoriginal
nkoriginal
Flag of Spain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can do this with javascript if you submit the form to a small iframe on the page.
Beware you will have no feedback if save fails.

Somthing like this:

<form id="myForm" name="myForm" action="save.asp" target="_top" method="post">
<input type="submit" value="save">
<input type="button" value="save & logout" onClick="JavaScript:document.getElementById('myForm').target='saveFrame';document.getElementById('myForm').submit();window.location.href='logoutpage.asp'">
</form>
<iframe width=1 height=1 src="blank.html" id="saveframe" name="saveframe">

Open in new window

Setting additonal parameters in the iframe tag hides it more:
border=0 frameborder=0 scrollbars=0