codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Please assist with verfication code  sskaar07 at 15:35 on Friday, May 27, 2005
 

Hello!

I have the following javascript code to verify fields in my form are filled out. However, when the logic returns false my form resets. Could you please tell me how to prevent this from happening? Your help is GREATLY appreciated!

Thank you,

Sandy

<script language="JavaScript">
<!--
function sendMail() {
if (document.forms[0].RequesterName.value == "") {
alert("No Requester has been specified!");
return false;
}
if (document.forms[0].RequesterID.value == "") {
alert("No Requester ID has been entered!");
return false;
}
if (document.forms[0].AssocName.value == "") {
alert("No Associate Name has been entered!");
return false;
}
if (document.forms[0].AssocID.value == "") {
alert("No Associate ID has been entered!");
return false;
}
if (document.forms[0].Issue.value == "") {
alert("No issue has been entered!");
return false;
}
// Construct a mailto: URL with all the details:
document.forms[0].action = "mailto:mwcc-databases@uscellular.com"+
"?subject=" + "PTP Trouble Ticket";
//Instructs the user to say OK to the mail server security prompt
alert("Your ticket will now be submitted. Please select OK to the next prompt");
// Redirects the user to the home page:
document.location="http://cellsite/customerservice/metrics/CDT/index.html";
return true;
}
//-->
</script>

  Re: Please assist with verfication code  Troy Wolf at 01:03 on Monday, June 06, 2005
 

Here is my guess, Sandy. The form is not resetting, it is refreshing from the server. There is a difference. In your FORM tag, make sure you do it like this.
<form onsubmit="return sendMail()">

The "return" is critical. Without that, your form will submit regardless of your validation.

An odd part of your script is that if validation succeeds, you navigate the user to another page. If you do that, then how are you supposed to submit the form? Instead, submit the form, and have the page that is returned after you process the form navigate to the new page. Or you can use a server-side redirect which would be smoother.
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Please assist with verfication code  sskaar07 at 17:53 on Monday, June 06, 2005
 

Troy,

Thank you, this resolved the form from refreshing. The only problem I have now is that my form won't submit. Sorry if I sound novice - the only forms I've built were in ASP but this site's server doesn't support it :-(

My Form tag looks like this:
<form name="PTPTroubleTicket" method="post" enctype="text/plain" onSubmit="SendMail()">

and my Submit button tag looks like this:
<input type="submit" value="Submit" onClick="Submit">

The validation works great but I am not getting the Posted email.

The reason I have the form forwarding was that it was submitting and then forwarding upon proper validation. The form was working but would just refresh if it returned false.

Not sure what I'm doing wrong. Thank you for your help it is Greatly appreciated as this is a work project that will help our team process trouble tickets more efficiently.

Thanks again,

Sandy

  Re: Please assist with verfication code  Troy Wolf at 18:27 on Monday, June 06, 2005
 

I'm a bit confused as you say I helped you get the form validation working, but yet it appears you aren't using my tips.

If you can strip down your page to the bare essentials to reproduce the problem, then post that, I can give you a sure solution. But until that time, try these few suggestions:

Remove the enctype attribute from your form tag. Is it wrong? I don't know, I just never use it unless I need to specifically indicate multipart for file uploads. So removing it is a safe thing to do in case you have it wrong and it is causing problems.

Add an action attribute to your form. Without this, the form should submit to the same page that produced the form. If that's what you wanted, then this should work without the action attribute. I always specify the action, so let's do that.

Temporarily remove the onsubmit attribute to see if your form will submit normally. Once you have that working, then go back and add in the validation script.

May I suggest you change your submit button to a type="button" rather than a type="submit". This way your form does not have a submit button. Set the onclick action of the "submit" button to be your validation script.
<input type="button" value="Submit" onClick="sendMail()">


Then, in your sendMail() function, if validation passes, add this line:
document.PTPTroubleTicket.submit();

Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Please assist with verfication code  sskaar07 at 19:56 on Monday, June 06, 2005
 

Troy,

Hi, sorry I posted the wrong thing - I have this working :-)
Now I just need it to either close the window or redirect to the home page after it submits. I know either you or someone has replied on that to another post so I think I can dig it up!

Thanks again!

The final code btw was:
<script language="JavaScript">
<!--
function sendMail() {
if (document.forms[0].Center.options[document.forms[0].Center.options.selectedIndex].text == "Select Center"){
alert("No center has been entered!");
return false;
}
// Construct a mailto: URL with all the details:
document.forms[0].action = "mailto:mwcc-databases@uscellular.com"+
"?subject=" + "PTP Trouble Ticket";

//Instructs the user to say OK to the mail server security prompt
//alert("Your ticket will now be submitted. Please select OK to the next prompt");
document.PTPTroubleTicket.submit();
return true;

}
//-->
</script>

My form tag is like this:

<form name="PTPTroubleTicket" method="post">

And my button is:
<input type="button" value="Submit" onClick="return sendMail()">




  Re: Please assist with verfication code  Troy Wolf at 20:08 on Monday, June 06, 2005
 

Close the current window:
self.close();


Redirect the current window:
document.location = "
" target=_blank>http://www.snippetedit.com";


<Added>

That code got messed up, but it's

document.location = '/forum/otherpage.htm';
Troy Wolf: site expert
SnippetEdit Website Editor


  Re: Please assist with verfication code  sskaar07 at 20:14 on Monday, June 06, 2005
 

Thank you so much!

If you ever have a question about MS Access let me know - it's what I do for a living - not this for sure LOL








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  matrix addition
•  Re: Storing data from HTML to Excel or TXT
•  Re: function within loop problem
•  Re: Ô‡´ò¥¯¥é¥Ö¤à ¥Æ©`¥é©`¥á¥¤¥É£ò£±£±¥¢¥¤¥¢¥ó ¤Î£··¬ ¤Ç¤¹
•  Re: Replace
•  Re: タイトリスト AP2アイアン 712ã�®æƒ…å �
•  Re: SMS from Perl using HTTP request
•  Re: Charl Schwartzel
•  Re: Adhyayan - Annual Student Conference and Online Coding Festival


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2013