?
Solved

how to redirect to a page once the form(mailto) is submitted.

Posted on 2003-03-04
26
Medium Priority
?
452 Views
Last Modified: 2008-02-01
These are part of my codes:

function redirect()
{
setTimeout('this.document.location.href="C:/a_Bak_William/thank_you.htm"',2500);
}
.........
.........
.........
<form action="mailto:abc@abc.com" method="post"
          enctype="text/plain" name="mailForm"
           onSubmit="return validateEmail() && checkFields() && mailIt(this) && redirect()">
          ..........................
    <p><input type="submit" value="Submit"></p>
</form>    

Once i click the submit button, there will be pop up Microsoft Internet Explorer box saying "This form is being submitted using email, etc...However if i click cancel, it redirect to the thank_you page immediately instead of remain on the same page.

Is there any way that i can do using javascript instead of doing on the server side or using cgi script?
Please help me experts....

thanks in advance.
0
Comment
Question by:cozyboi
[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
  • 8
  • 5
  • 4
  • +3
26 Comments
 
LVL 4

Expert Comment

by:boxy73
ID: 8063353
I'm not sure because I don't have all your code, but I think you should not use setTimeOut directly with location.href.

For example, you could insert that code in a function called fncRedirection (). This should be the function called from redirect () in the setTimeOut.

function redirect()
{
    setTimeout ('fncRedirection ();',2500);
}

You could define a global variable bolRedirect = true;

And if you receive from the modal window the cancel operation, just change bolRedirect = false;

Finally, the fncRedirection should be something like:


fncRedirection ()
{
  if (bolRedirect)
this.document.location.href="C:/a_Bak_William/thank_you.htm"';
}
0
 
LVL 19

Expert Comment

by:webwoman
ID: 8065129
First of all, you do NOT want a link with a drive letter.

Second, find out if your ISP/hosting company has a REAL form handler. Chances are they do, and it will actually WORK as opposed to mailto, which may or may not work, and you have no control over which it is.
0
 

Author Comment

by:cozyboi
ID: 8068823
To boxy73,

How do I control the modal window? where should i insert

bolRedirect=false? The modal window pop up automatically

and there is no way I can control it.
0
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.

 

Author Comment

by:cozyboi
ID: 8068858
To webwoman,

Can I explain to me in more detail? Does it mean

that i should upload it to the web using my hosting

company?

At moment, I want to try on local drive to see whether

it works or not.
0
 
LVL 5

Expert Comment

by:elhy
ID: 8070118
u don't have to specify the full path. if this form lies in the same directory (a_Bak_William) just specify thank_you.htm will do. I've modified your redirect function. See if this works.


function redirect()
{
  if(validateEmail() && checkFields() && mailIt(document.mailForm)){
setTimeout('this.document.location.href="thank_you.htm"',2500);
  }
}
.........
.........
.........
<form action="mailto:abc@abc.com" method="post"
         enctype="text/plain" name="mailForm"
          onSubmit="return redirect();">
         ..........................
   <p><input type="submit" value="Submit"></p>
</form>  
0
 

Author Comment

by:cozyboi
ID: 8070269
To elhy,

I don't think it has any difference from my previous

coding. I show some more of my coding, hope you or other

experts can help me, thanks


function redirect()
{
     window.location.href="C:/a_Bak_William/thank_you.htm";


}


function mailIt(form1) {
  var name = form.Name.value
  var handphone = form.Handphone.value
  var email = form.Email.value
  var DA1DD = form.DA1DD.value
  var DA1MM = form.DA1MM.value
  var DA1YY = form.DA1YY.value
  var DA1Hr = form.DA1Hr.value
  var DA1Min = form.DA1Min.value
  var DA1AMPM = form.DA1AMPM.value
  var RA1D = form.RA1D.value
  var PurposeApp1 = form.PurposeApp1.value
 
 
  var userInfo = ""

  userInfo += " " + name + "\n\n"
  userInfo += "Handphone= " + handphone + "\n\n"
  userInfo += "Email= " + email + "\n\n"
  userInfo += "Date of 1st Appointment= " + DA1DD + " " + DA1MM + " " + DA1YY + "  " + DA1Hr + ":" + DA1Min + DA1AMPM + "\n\n"
  userInfo += "Purpose of 1st Appointment= Remind patient " + RA1D + " before appointment time." + "\n\n"
  userInfo += "Purpose of 1st Appointment= " + PurposeApp1 + " on " + DA1DD + " " + DA1MM + " " + DA1YY + "  " + DA1Hr + ":" + DA1Min + DA1AMPM + "\n\n"
 
 
  try{
  userInfo += "Date of 2nd Appointment= " + form.DA2DD.value + " " + form.DA2MM.value + " " + form.DA2YY.value + "  " + form.DA2Hr.value + ":" + form.DA2Min.value + form.DA2AMPM.value + "\n\n"
  userInfo += "Purpose of 2nd Appointment= Remind patient " + form.RA2D.value + " before appointment time." + "\n\n"
  userInfo += "Purpose of 2nd Appointment= " + form.PurposeApp2.value + " on " + form.DA2DD.value + " " + form.DA2MM.value + " " + form.DA2YY.value + "  " + form.DA2Hr.value + ":" + form.DA2Min.value + form.DA2AMPM.value + "\n\n"
  }catch(e){}
  form1.Name.value = userInfo
  return true
 
  document.write("<html><head></head><body>")
  document.write("<p><h3>Thank You</h3></p>")
  docment.write("</body></html>")

}
........
........
........
........

<form name=form>
......
"form fields etc...."
......
</form>

<form action="mailto:sms@mhchealthcare.com" method="post"
          enctype="text/plain" name="mailForm"
           onSubmit="return validateEmail() && checkFields() && mailIt(this) && setTimeout('redirect()',2500)">
    <input type="hidden" name="Name" >
    <p><input type="submit" value="Submit"></p>
</form>  
0
 

Author Comment

by:cozyboi
ID: 8070271
To elhy,

I don't think it has any difference from my previous

coding. I show some more of my coding, hope you or other

experts can help me, thanks


function redirect()
{
     window.location.href="C:/a_Bak_William/thank_you.htm";


}


function mailIt(form1) {
  var name = form.Name.value
  var handphone = form.Handphone.value
  var email = form.Email.value
  var DA1DD = form.DA1DD.value
  var DA1MM = form.DA1MM.value
  var DA1YY = form.DA1YY.value
  var DA1Hr = form.DA1Hr.value
  var DA1Min = form.DA1Min.value
  var DA1AMPM = form.DA1AMPM.value
  var RA1D = form.RA1D.value
  var PurposeApp1 = form.PurposeApp1.value
 
 
  var userInfo = ""

  userInfo += " " + name + "\n\n"
  userInfo += "Handphone= " + handphone + "\n\n"
  userInfo += "Email= " + email + "\n\n"
  userInfo += "Date of 1st Appointment= " + DA1DD + " " + DA1MM + " " + DA1YY + "  " + DA1Hr + ":" + DA1Min + DA1AMPM + "\n\n"
  userInfo += "Purpose of 1st Appointment= Remind patient " + RA1D + " before appointment time." + "\n\n"
  userInfo += "Purpose of 1st Appointment= " + PurposeApp1 + " on " + DA1DD + " " + DA1MM + " " + DA1YY + "  " + DA1Hr + ":" + DA1Min + DA1AMPM + "\n\n"
 
 
  try{
  userInfo += "Date of 2nd Appointment= " + form.DA2DD.value + " " + form.DA2MM.value + " " + form.DA2YY.value + "  " + form.DA2Hr.value + ":" + form.DA2Min.value + form.DA2AMPM.value + "\n\n"
  userInfo += "Purpose of 2nd Appointment= Remind patient " + form.RA2D.value + " before appointment time." + "\n\n"
  userInfo += "Purpose of 2nd Appointment= " + form.PurposeApp2.value + " on " + form.DA2DD.value + " " + form.DA2MM.value + " " + form.DA2YY.value + "  " + form.DA2Hr.value + ":" + form.DA2Min.value + form.DA2AMPM.value + "\n\n"
  }catch(e){}
  form1.Name.value = userInfo
  return true
 
  document.write("<html><head></head><body>")
  document.write("<p><h3>Thank You</h3></p>")
  docment.write("</body></html>")

}
........
........
........
........

<form name=form>
......
"form fields etc...."
......
</form>

<form action="mailto:abc@abc.com" method="post"
          enctype="text/plain" name="mailForm"
           onSubmit="return validateEmail() && checkFields() && mailIt(this) && setTimeout('redirect()',2500)">
    <input type="hidden" name="Name" >
    <p><input type="submit" value="Submit"></p>
</form>  
0
 
LVL 5

Expert Comment

by:elhy
ID: 8070704
questions:

1. Why do you have two forms? The submit btn etc should be within the same form tag.

Not sure if you can control that confirmation msg coz its brought up by IE/windows. I doubt so. But if anyone knows how to control please post here. I'm interest to know too.
0
 
LVL 4

Expert Comment

by:boxy73
ID: 8071039
Can't you pass the window object as a parameter from your main window the the popup one? If so, you could use it to access the global variable bolRedirect and change its value.



0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8072032
You can use the confirm()

function submitForm(){

}
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8072102
You can use the confirm()

function submitForm(){
   if (confirm("will be emailed")) {
      // call all the email function here
      // and return false if an error occurs
      validateEmail();
      checkFields();
      mailIt(this);
      setTimeout('redirect()',2500);
   }    
}
function redirect(){
   document.location.href = "thanks.html";
}


<form action="mailto:abc@abc.com" method="post"
         enctype="text/plain" name="mailForm"
          onSubmit="submitForm()">
   <input type="hidden" name="Name" >
   <p><input type="submit" value="Submit"></p>
</form>


mayby it is not correct, but i'm giving a shot
0
 

Author Comment

by:cozyboi
ID: 8076423
To boxy73,

Can you explain to me further as in produce some codings

or examples? Coz I think there is no way i can control the

confirmation msg box.

Thanks alot.
0
 
LVL 5

Expert Comment

by:elhy
ID: 8077224
Commodus2:

I thought this statement "if (confirm("will be emailed")) {" will create a new confirmation popup?? Please advice if I'm wrong.
0
 
LVL 4

Expert Comment

by:boxy73
ID: 8078065
What are you using for the popup window? A window.showModalDialog (popup-address, parameters, ...); ?

If so, in the parameters just pass window.

In the modal window, just type at the beginning of the Javascript code:

var objParent = window.dialogArguments;

And now you will have full access to parent's global Javascript variables (including bolRedirect) and functions.

If not using showModalDialog, what are you using for the popup window?


0
 

Author Comment

by:cozyboi
ID: 8078107
To boxy73,

That is a Email confirmation msg box. Is not a popup

window.

The confirmation msg box is brought up by IE/Windows as

what elhy has mentioned.
0
 
LVL 4

Expert Comment

by:boxy73
ID: 8080183
In that case don't use that confirm. Build your our confirm as a window.showModal....  and use it as I've told you. It would be easy, wouldn't it?
0
 
LVL 5

Expert Comment

by:elhy
ID: 8085346
boxy73,

but this confirmation box cannot be prevented. windows activate it whenever browser auto send email out. This is one of the security feature of windows. I'm not sure if there are any option for you to disable, as far as i know, it can't be opt out.
0
 

Author Comment

by:cozyboi
ID: 8085354
yah i agree with elhy...

This have given me a great headache
0
 
LVL 19

Expert Comment

by:webwoman
ID: 8087632
OF courese, if you didn't use mailto, but handled it on the server like a REAL form, you wouldn't have ANY of the problems you're having.

If you want to do this correctly, you CANNOT test it on your machine unless you have a webserver/SMTP set up. If you insist on trying to test it out locally WITHOUT that, you CANNOT do it correctly.

You DO realize that you have NO control over what you get? You might get an attachment with the querystring, a nice email, or nothing. You have NO WAY to know, and NO WAY to make the user send it, or keep them from changing it. Also, if there's no mail client installed, it WILL NOT WORK AT ALL. Use web based mail? Won't work. Use a proprietary mail client (like AOL)? Won't work. Don't send the mail because you don't know why it popped up? Won't work. And a lot of people will just get a BLANK mail window and won't do ANYTHING.
0
 

Author Comment

by:cozyboi
ID: 8099732
To webwomen:

so wat u i should do now? i would like to hear ur advice.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 8107824
Contact whoever hosts your site, and ask THEM. You can't do something that's not supported on the server, and they most likely already have something you can use.
0
 
LVL 5

Expert Comment

by:elhy
ID: 8108040
Hmm....that requires other skills such as writing of CGI, Perl, ASP, Cold Fusion, ASP.NET, JSP etc (depending on what the server support).
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8109472
I'd use PHP to mail. It is so easy... easy to install. free. so almost every host supports it. looks like c(++).
www.php.net
0
 
LVL 19

Accepted Solution

by:
webwoman earned 300 total points
ID: 8109899
If the hosting service already has something set up and installed, it takes NO skill other than following directions. And most will have something set up. Certainly it's a lot easier than what they've done so far (that hasn't worked).

Of course, unless you contact them and ask, you won't know.
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 10097385
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Accept: webwoman {http:#8109899}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
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 …
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

762 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