Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Stop the submit action

Posted on 2000-03-23
6
Medium Priority
?
165 Views
Last Modified: 2013-12-25
I have a Perl Script that writes out a HTML form  and some javascript functions. The functions(behind the submit button) check if the form details have been filled out correctly or not. If the function fails (e.g. bad details) I want to cancel the POST rather than requery my Perl Script. Can anyone tell me how to do this ? T.I.A.
0
Comment
Question by:j_machale
  • 3
  • 3
6 Comments
 
LVL 10

Accepted Solution

by:
makerp earned 240 total points
ID: 2650697
first of all put an obSubmit event in your form. i.e

<FORM...MET..... onSubmit()="return validateFunction(this)">

then simply code your validate function to validate the fields and return false if it fails

i.e.

function validateFunction(f)
{
      if(f.name.value.length == 0)
      {
            alert("bad input !");
            return false
      }
      else
      {
            return true;
      }
}

returning false on any event will cause them not to happern.
0
 

Author Comment

by:j_machale
ID: 2653103
Adjusted points from 50 to 60
0
 

Author Comment

by:j_machale
ID: 2653104
Sorry makerp , I need a little more help as this does not seem to stop the POST. My code outline is as follows

<form name="frmHolidays" action="$script" method="POST" onSubmit()="return checkForm(this)">
......
<input type="submit" value="Continue" name="cmdConfirm" tabindex="1"  
<input type="reset" value="Clear Form" name="cmdClear">
.......
<SCRIPT LANGUAGE="JavaScript">

function checkForm(myobj) {
return false;
}

This code will still requery the script. Do I have the right idea ?
0
How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

 
LVL 10

Expert Comment

by:makerp
ID: 2653152
put the script in the head of the html ..
i.e

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
 function checkForm(myobj)
 {
      return false;
 }
</SCRIPT>
</HEAD>

youir onsubmit should be

onSubmit="return checkForm(this)"

not

onSubmit()="return checkForm(this)"

lose the brackets after onSubmit
 

0
 

Author Comment

by:j_machale
ID: 2653353
Cheers makerp, I didn't need to move the JS it was just the () after the onSubmit !!!. Thanks.

P.S. There were in your original code
0
 
LVL 10

Expert Comment

by:makerp
ID: 2653527
whoops .. sorry
0

Featured Post

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.

Question has a verified solution.

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

This tutorial will discuss fancy secure registration forms, with AJAX technology support. In this article I assume you already know HTML and some JS. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you mig…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
Suggested Courses

876 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