Solved

Javascript submission of form with redirect

Posted on 2008-09-30
3
765 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery scrollTop 2 40
Need to click button twice to get results 2 32
Randomize in Owl Carousel v1.3.2 6 19
Interview question Javascript, database 12 29
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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…

911 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

22 Experts available now in Live!

Get 1:1 Help Now