Solved

Stop the submit action

Posted on 2000-03-23
6
159 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Making a simple AJAX shopping cart Couple years ago I made my first shopping cart, I used iframe and JavaScript, it was very good at that time, there were no sessions or AJAX, I used cookies on clients machine. Today we have more advanced techno…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 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