Solved

Help with onSubmit syntax ...

Posted on 2001-06-04
17
453 Views
Last Modified: 2012-06-22
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
Comment
Question by:mmoneal
[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
  • 7
17 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152442
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152444
Ooops


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

Michel
0
 
LVL 1

Expert Comment

by:GreyWolf_tx
ID: 6152484
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
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.

 

Author Comment

by:mmoneal
ID: 6152502
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
 

Author Comment

by:mmoneal
ID: 6152505
oops .. posted too soon .. that one was for Michel.  I'll try yours now, Greywolf ...
0
 

Author Comment

by:mmoneal
ID: 6152576
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152609
Mine should work - hang on

Michel
0
 

Author Comment

by:mmoneal
ID: 6152616
okay, Michel .. thanks ....
0
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 50 total points
ID: 6152629
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
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152634
GreyWolf: navigate is IE only and is identical to window.location='...' or location.href='...'

Michel
0
 

Author Comment

by:mmoneal
ID: 6152666
Michel ..

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

Hmm ... any other suggestions?

Thanks! :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152679
I need the complete page as it looks now - did you refresh your cache?

Michel
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152686
By the way, change
mailForm_Validator(Obj)
to
mailForm_Validator(theForm)
0
 

Author Comment

by:mmoneal
ID: 6152699
yes, I refresh every time. Let me try changing the code on the last comment .. brb.  THANKS! :)
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152722
A question: Are all the fields you validate text fields?
If so the script can be vastly shortened

Michel
0
 

Author Comment

by:mmoneal
ID: 6152730
beautiful!!! It works!!!! THANK YOU!!! :))))
I made this change:

mailForm_Validator(theForm)


and now it works.  THANKS AGAIN!!! :)))
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 6152755
Glad to help.

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

Michel
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
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.
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…

734 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