Solved

Javascript submission of form with redirect

Posted on 2008-09-30
3
770 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

751 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