Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript submission of form with redirect

Posted on 2008-09-30
3
Medium Priority
?
778 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 1500 total points
ID: 22611810
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
ID: 22612701
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
ID: 22612710
Setting additonal parameters in the iframe tag hides it more:
border=0 frameborder=0 scrollbars=0
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

916 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