?
Solved

JavaScript: Submit form after validation

Posted on 2005-04-04
6
Medium Priority
?
534 Views
Last Modified: 2011-04-14
<form name="new_record" method="post" action="../jsp/new.jsp" onSubmit="return chkFormular()">

chkFormular() performs some client-side checks and returns true/false (implicitely by 'return').
Is there a way to get the value of 'return chkFormular()' (--> true/false), just before submitting?
0
Comment
Question by:go4java
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 13696059
What do you need to do?

You can probably embed what you want into the chcFormular() function

example:


<script>

function chkFormular(){
    var value = true;
    alert(value);
    return value;
}
</script>
<form name="new_record" method="post" action="../jsp/new.jsp" onSubmit="return chkFormular()">
<input type="submit">
</form>
0
 

Author Comment

by:go4java
ID: 13696074
I need to:
1. evaluate the true/false-return from onSubmit="return chkFormular()
2. if true --> disable submit button --> call new.jsp
3. if false --> enable submit button --> return to form

...I'd like to call 2 functions in 'onSubmit', but I have the feeling that only the first function call works.
0
 
LVL 32

Accepted Solution

by:
Batalf earned 1500 total points
ID: 13696097
You can do all the same function.

Example:

<body>
<script>
function chkFormular(){
    var okToSubmit = true;
    if(okToSubmit){
        document.new_record.mySubmit.disabled=true;    
    }
    return okToSubmit;
}
</script>
<form name="new_record" method="post" action="../jsp/new.jsp" onSubmit="return chkFormular()">
<input type="submit" name="mySubmit">
</form>
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Expert Comment

by:jeff_ching
ID: 13696100
Hi,
if you using onSubmit event, the code should be:
<form name="new_record" method="post" action="../jsp/new.jsp" onSubmit="chkFormular()">


I will perfer this way,
<html>
<head><title>test</title></head>

<script language='JavaScript'>
<!--//
function FormSubmit(eform) {
   if ( chkFormular(eform) )
      eform.submit();
   else
   {
      //other action      
   }
}

function chkFormular(eform) {
   //your chekcing code
   <!--
   if (eform.otherCtrName.value == 'xxx')
      return true
   else
      return false;
   -->
}
//-->
</script>
<body>
<form name="new_record" method="post" action="../jsp/new.jsp">
<!--
your code
...
-->
<input type=button value='Submit' onClick='FormSubmit(this.form)'>
</form>
</body>
</html>
0
 
LVL 32

Expert Comment

by:Batalf
ID: 13696120
go4java,

thanks for the points!

Just fyi: According to the EE guidelines, you should always give grade "A" if a comment solved your question. If not, you should give the experts a chance to earn an "A" grade. The grades at EE doesn't work as school grades:-)

Batalf
0
 

Expert Comment

by:jeff_ching
ID: 13696156
Hi,
Batalf's concept is right and my suggested codes are:

<html>
<head><title>test</title></head>

<script language='JavaScript'>
<!--//
function FormSubmit(eform) {
   if ( chkFormular(eform) )
   {
      eform.submitButton.disabled = true;      
   }
   else
   {
      eform.method = 'POST';
      eform.action = "../jsp/new.jsp";    
      eform.submitButton.disabled = false;
      eform.submit();
   }
}

function chkFormular(eform) {
   //your checking code e.g
   <!--
   if (eform.otherCtrName.value == 'xxx')
      return true
   else
      return false;
   -->
}
//-->
</script>
<body>
<form name="new_record">
<!--
your code
...
-->
<input type=button name='submitButton' value='Submit' onClick='FormSubmit(this.form)'>
</form>
</body>
</html>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

752 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