Solved

Stop the submit action

Posted on 2000-03-23
6
161 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 60 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

Suggested Solutions

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

790 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