Solved

Stop the submit action

Posted on 2000-03-23
6
158 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
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 …
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now