Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 458
  • Last Modified:

Help with onSubmit syntax ...

The following syntax doesn't quite work.  It DOES process the mailto form but it doesn't REDIRECT to the next page.

Can you help me correct the following syntax:

<FORM
  NAME="mailForm"
  ACTION="mailto:mmoneal@mindspring.com?subject=testing"
  METHOD="post"
  ENCTYPE="text/plain"
  onSubmit="return mailForm_Validator(this)"; "window.setTimeout("location.href='form_test_thanks.htm'",1000)">
0
mmoneal
Asked:
mmoneal
  • 9
  • 7
1 Solution
 
Michel PlungjanIT ExpertCommented:
The return is the last statement executed also you have too many quotes.
Use this:

onSubmit="if (mailForm_Validator(this) window.setTimeout('location.href=\'form_test_thanks.htm\'',1000); return true; else return false">

Michel
0
 
Michel PlungjanIT ExpertCommented:
Ooops


onSubmit="if (mailForm_Validator(this) {
window.setTimeout('location.href=\'form_test_thanks.htm\'',1000);
return true;
}
else return false">

Michel
0
 
GreyWolf_txCommented:
Your onSubmit syntax needs to be contained in a single set of double quotes. Try the following:
onSubmit="'return mailForm_Validator(this)'; 'window.setTimeout('location.href='form_test_thanks.htm', 1000)';"

But I don't have a lot of confidence in that working as there's just too many sets of qoutes. A more effective way of handling this would be to make a single onSubmit call, such as:

onSubmit="mailForm_Validator(this);"

and in your mailForm_Validator function include your return and on a positive response do the navigation to the Thank You page, like this:

function mailForm_Validator(Obj)
{
    {
    validation code;
    }
    if validation=true
    {
    window.navigate(form_test_thanks.htm);
    }
    else
    {
    window.navigate(some_other_message.htm);
    }
}

GreyWolf
   
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
mmonealAuthor Commented:
hmmm ...

Now it doesn't form validate or redirect.  (But it does send the mailto form)

Is there another way to write this part?
0
 
mmonealAuthor Commented:
oops .. posted too soon .. that one was for Michel.  I'll try yours now, Greywolf ...
0
 
mmonealAuthor Commented:
I really don't want the form to go to a page that says "go back and finish filling out the form, etc."

I want a pop up message to come up when the user hits the submit button if there is a field that needs to be filled out.  Then, when all required fields are filled out, it will send the mailto form and redirect to a thank you page.

See my entire code below.

<SCRIPT LANGUAGE="JavaScript">
<!--
       
function mailIt(form) {
  var data = document.dataForm
  var userInfo = ""


  userInfo += "Page Title:  " + document.title + "\n"
  userInfo += "Mailed From: " + document.location + "\n\n"

  form.mailBody.value = userInfo + data.body.value
  return true
}
// -->
</SCRIPT>


<script language="JavaScript">
<!--
function mailForm_Validator(Obj)
{
   {
   validation code;
   }
   if validation=true
   {
   window.navigate(form_test_thanks.htm);
   }
   else
   {
   if (theForm.Company_Name.value == "")
  {
    alert("Please enter a value for the \"Company Name\" field.");
    theForm.Company_Name.focus();
    return (false);
  }

  if (theForm.Contact_Name.value == "")
  {
    alert("Please enter a value for the \"Contact Name\" field.");
    theForm.Contact_Name.focus();
    return (false);
  }

  if (theForm.Street_Address.value == "")
  {
    alert("Please enter a value for the \"Street Address\" field.");
    theForm.Street_Address.focus();
    return (false);
  }

  if (theForm.City.value == "")
  {
    alert("Please enter a value for the \"City\" field.");
    theForm.City.focus();
    return (false);
  }

  if (theForm.Zip_Postal_Code.value == "")
  {
    alert("Please enter a value for the \"Zip or Postal Code\" field.");
    theForm.Zip_Postal_Code.focus();
    return (false);
  }

  if (theForm.Telephone_1.value == "")
  {
    alert("Please enter a value for the \"Telephone Number\" field.");
    theForm.Telephone_1.focus();
    return (false);
  }

  if (theForm.Hear_About_Cavalier.value == "")
  {
    alert("Please enter a value for the \"How You Heard About Cavalier\" field.");
    theForm.Hear_About_Cavalier.focus();
    return (false);
  }

  if (theForm.Permission.value == "")
  {
    alert("Please enter a value for the \"Permission\" field.");
    theForm.Permission.focus();
    return (false);
  }

  if (theForm.Permission.value.length > 3)
  {
    alert("Please enter at most 3 characters in the \"Permission\" field.");
    theForm.Permission.focus();
    return (false);
  }

  if (theForm.Authorizer_Name.value == "")
  {
    alert("Please enter a value for the \"Your Name\" field.");
    theForm.Authorizer_Name.focus();
    return (false);
  }

  if (theForm.Date.value == "")
  {
    alert("Please enter a value for the \"Date\" field.");
    theForm.Date.focus();
    return (false);
  }
  return (true);
}
//--></script>


<FORM
  NAME="mailForm"
  ACTION="mailto:mmoneal@mindspring.com?subject=testing"
  METHOD="post"
  ENCTYPE="text/plain"
  onSubmit="mailForm_Validator(this);">





I just tried the above and it doesn't work.  Any more suggestions?  I REALLY APPRECIATE YOUR HELP! Thanks SO MUCH! :)



0
 
Michel PlungjanIT ExpertCommented:
Mine should work - hang on

Michel
0
 
mmonealAuthor Commented:
okay, Michel .. thanks ....
0
 
Michel PlungjanIT ExpertCommented:
Sorry, missed a bracket-.


<SCRIPT LANGUAGE="JavaScript">
<!--
       
function mailIt(form) {
 var data = document.dataForm
 var userInfo = ""


 userInfo += "Page Title:  " + document.title + "\n"
 userInfo += "Mailed From: " + document.location + "\n\n"

 form.mailBody.value = userInfo + data.body.value
 return true
}
// -->
</SCRIPT>


<script language="JavaScript">
<!--
function mailForm_Validator(Obj)
{
  if (theForm.Company_Name.value == "")
 {
   alert("Please enter a value for the \"Company Name\" field.");
   theForm.Company_Name.focus();
   return (false);
 }

 if (theForm.Contact_Name.value == "")
 {
   alert("Please enter a value for the \"Contact Name\" field.");
   theForm.Contact_Name.focus();
   return (false);
 }

 if (theForm.Street_Address.value == "")
 {
   alert("Please enter a value for the \"Street Address\" field.");
   theForm.Street_Address.focus();
   return (false);
 }

 if (theForm.City.value == "")
 {
   alert("Please enter a value for the \"City\" field.");
   theForm.City.focus();
   return (false);
 }

 if (theForm.Zip_Postal_Code.value == "")
 {
   alert("Please enter a value for the \"Zip or Postal Code\" field.");
   theForm.Zip_Postal_Code.focus();
   return (false);
 }

 if (theForm.Telephone_1.value == "")
 {
   alert("Please enter a value for the \"Telephone Number\" field.");
   theForm.Telephone_1.focus();
   return (false);
 }

 if (theForm.Hear_About_Cavalier.value == "")
 {
   alert("Please enter a value for the \"How You Heard About Cavalier\" field.");
   theForm.Hear_About_Cavalier.focus();
   return (false);
 }

 if (theForm.Permission.value == "")
 {
   alert("Please enter a value for the \"Permission\" field.");
   theForm.Permission.focus();
   return (false);
 }

 if (theForm.Permission.value.length > 3)
 {
   alert("Please enter at most 3 characters in the \"Permission\" field.");
   theForm.Permission.focus();
   return (false);
 }

 if (theForm.Authorizer_Name.value == "")
 {
   alert("Please enter a value for the \"Your Name\" field.");
   theForm.Authorizer_Name.focus();
   return (false);
 }

 if (theForm.Date.value == "")
 {
   alert("Please enter a value for the \"Date\" field.");
   theForm.Date.focus();
   return (false);
 }
 return (true);
}
//--></script>
<FORM
 NAME="mailForm"
 ACTION="mailto:mmoneal@mindspring.com?subject=testing"
 METHOD="post"
 ENCTYPE="text/plain"
onSubmit="if (mailForm_Validator(this)) {
window.setTimeout('location.href=\'form_test_thanks.htm\'',1000);
return true;
}
else return false">
0
 
Michel PlungjanIT ExpertCommented:
GreyWolf: navigate is IE only and is identical to window.location='...' or location.href='...'

Michel
0
 
mmonealAuthor Commented:
Michel ..

The mailto form is sent, but it still doesn't validate or redirect to the next page.

Hmm ... any other suggestions?

Thanks! :)
0
 
Michel PlungjanIT ExpertCommented:
I need the complete page as it looks now - did you refresh your cache?

Michel
0
 
Michel PlungjanIT ExpertCommented:
By the way, change
mailForm_Validator(Obj)
to
mailForm_Validator(theForm)
0
 
mmonealAuthor Commented:
yes, I refresh every time. Let me try changing the code on the last comment .. brb.  THANKS! :)
0
 
Michel PlungjanIT ExpertCommented:
A question: Are all the fields you validate text fields?
If so the script can be vastly shortened

Michel
0
 
mmonealAuthor Commented:
beautiful!!! It works!!!! THANK YOU!!! :))))
I made this change:

mailForm_Validator(theForm)


and now it works.  THANKS AGAIN!!! :)))
0
 
Michel PlungjanIT ExpertCommented:
Glad to help.

You may want to change ,1000 to ,3000 to give the form a little longer to submit

Michel
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 9
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now