Solved

Form problem, load subsequent page w/o cgi on submit

Posted on 1997-11-18
9
277 Views
Last Modified: 2012-05-04
So, I've got this form that I want to post via email, but I want to load a "success" page after the form has been submitted. The script & form below _should_ work, but the submit() function doesn't seem to function as specified. Interestingly enough, if I add a regular submit button and
add the line "document.surveyForm.Submit.click()" it works fine...but then I've got two submit buttons, err...kinda stupid. I need a solution that either enables me to load a success page after submission using a regular submit button, OR a method for submitting a form using a method included in an onClick handler. Help?
<CODE>
<FORM ACTION="mailto:arno@sirius.com?subject=Test Survey" METHOD="POST"
ENCTYPE="text/plain" NAME="surveyForm">

<SCRIPT LANGUAGE="JavaScript">
<!--hide script
        function sendIt(targetHREF)
        {       document.surveyForm.submit()
                self.location.href=targetHREF
        }
// -->
</SCRIPT>

What is your name?<BR>
<INPUT NAME="name" TYPE="Text" VALUE="" SIZE="32" MAXLENGTH="32"> <P>
<INPUT NAME="Submit Form" TYPE="Button" VALUE="Submit Form"
onClick="sendIt('success.html')">
</FORM>
</CODE>
0
Comment
Question by:arnoh
[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
9 Comments
 

Author Comment

by:arnoh
ID: 1274281
It seems the submit() method was deactivated for security reasons. So, the only thing that's going to work is some sort of function that loads a success page after the form is submitted using a standard TYPE="submit" input.
0
 
LVL 5

Expert Comment

by:Christian_Wenz
ID: 1274282
arnoh is right. submit() works, but not if the form ACTION is mailto: !!
0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 1274283
This is what I use to get a success page to show up.  Enter it just before the </FORM> tag.
<INPUT TYPE="hidden" NAME="next-url" VALUE="next_page.html">
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 

Author Comment

by:arnoh
ID: 1274284
I'm not sure I understand how a hidden input will load a page just by virtue of its presence?! Nonetheless I tried the solution suggested above...with no result. Is there an additional script that needs to be added to make the hidden input work?
0
 
LVL 6

Expert Comment

by:tecbuilder
ID: 1274285
I did some digging and evidentally the Name="next_url" is a variable of some type for a CGI script.  I didn't realize this until you said that it didn't work.  Sorry.

The issue that the other comments made about the security issues for submitting an action of mailto, I believe are false.  According to Netscape's JS Guide you can use a mailto as an action.  However, the user will be notified that information is about to be sent via email.  They then have the choice of allowing or dis-allowing the email from being sent.

The problem of going to another page once the email has been sent I don't believe can be done without a CGI script for a single button.  The security just won't let you.
0
 
LVL 4

Expert Comment

by:jshamlin
ID: 1274286
First, to echo what's been said - submit() won't work if the ACTION is mailto: - too many people were compiling SPAM-lists of everyone who visited the page (by submitting invisible mailto: forms) - but there is a way to make this work ...

Instead of <INPUT TYPE="button">, use <INPUT TYPE="submit"> - which is designed to submit the form withour recourse to JavaScript.  That will make sure the e-mail gets sent.

In that tag (the <INPUT TYPE="submit">) include an onClick event handler ..

onClick="this.location='newpage.html';"

This is the important bit: OMIT the HREF - document.location.href is a read-only parameter that returns the URL of the present document as a string that can be parsed for evaluation.  When you assign document.location.href a value, it takes on that new value  (strangely enough - should return an error, theoretically) as if it were any other string variable,- it does not serve to redirect the user to another page.  document.location = '[url]'; will do the trick.


0
 

Author Comment

by:arnoh
ID: 1274287
Didn't fix it. The problem here seems to be that the onClick handler doesn't work on a submit type input...ergh. I've never had the problem with setting location.href, works fine for me in other code. Here's the really weird part. If I put an alert statement in the onClick handler, it executes the alert. It just won't execute a page load.
0
 
LVL 10

Accepted Solution

by:
kollegov earned 100 total points
ID: 1274288
Just use regular submit button
but set timeout to change document location later
from onSubmit handler.

<SCRIPT LANGUAGE="JavaScript">
<!--hide script
function sendIt(targetHREF)
{setTimeout("document.location=targetHREF",500);}
// -->
</SCRIPT>



<FORM ACTION="mailto:arno@sirius.com?subject=Test
Survey" METHOD="POST"
ENCTYPE="text/plain" NAME="surveyForm" onSubmit='sendIt("thanks.html")'>

What is your name?<BR>
<INPUT NAME="name" TYPE="Text" VALUE=""
SIZE="32" MAXLENGTH="32"> <P>
<INPUT NAME="Submit Form" TYPE="submit"
 VALUE="Submit Form"
</FORM>
0
 

Author Comment

by:arnoh
ID: 1274289
Though it's still a kludge of sorts...I think it's the best JS is going to offer. Thanks to all for the help.
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
This article discusses how to implement server side field validation and display customized error messages to the client.
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

623 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