Solved

Javascript submission of form with redirect

Posted on 2008-09-30
3
764 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:markm5i
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
nkoriginal earned 500 total points
Comment Utility
Try this...
Check the page name.
To redirect any page in asp you need to use, response.redirect("")
You can call result.asp and put the redirect there, is up to you
Let me know if you need something else

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<html>
<head>
<title>Untitled Document</title>
</head>

<body>

<%
if request.Form("submit") = "submit" then

' code to insert in DB

response.Redirect("show.html")

end if
%>

<form action="result.asp" method="get">
<input type=text name=xxx>
<input name="submit" type=submit value="submit">
</form>
</body>
</html>
0
 
LVL 7

Expert Comment

by:bluV11t
Comment Utility
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

0
 
LVL 7

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now