473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Form should submit only when all data is filled

vikas251074
198 100+
I now creating material outpass for taking material out from our campus.
In the first page, persons name taking material out, issue_date, department, vehicle_no, driver_name, purpose, received_by and remarks is entered.
In the second page no. of materials to taken out is given.
In the third page, it creates no. of row as mentioned in the second page. suppose 5. Five row is created. Fields in this page are material_name, company_sr_no, department_sr_no, quantity, weight, remarks. Two buttons are there. One is 'Cancel' and other is form submit button 'Add'.

Here in third page, one problem regular occurs. When enter key is pressed by mistake without filling all details, the form is submitted (i.e. 'Add' button is pressed). How can I stop this? I want to there should be no effect of enter key without filling all the five row. If any one tries to click 'Add', 'Add' button should not work untill and unless all the five rows of material are filled.

Thanks and regards,
Vikas
Jun 2 '08 #1
11 1699
gits
5,390 Expert Mod 4TB
hi ...

add an onsubmit-handler to your form and call a javascript function that validates all the fields:

Expand|Select|Wrap|Line Numbers
  1. <form action="what_ever" onsubmit="return validate_form(this);">
the function should check all fields and has to return either true or false depending on your validation:

Expand|Select|Wrap|Line Numbers
  1. function validate_form(node) {
  2.     var val = true;
  3.  
  4.     // validation code sets the val that should be returned
  5.     // note the parameter node is a reference to your form already
  6.  
  7.     return val;
  8. }
  9.  
kind regards
Jun 2 '08 #2
vikas251074
198 100+
hi ...

add an onsubmit-handler to your form and call a javascript function that validates all the fields:

Expand|Select|Wrap|Line Numbers
  1. <form action="what_ever" onsubmit="return validate_form(this);">
the function should check all fields and has to return either true or false depending on your validation:

Expand|Select|Wrap|Line Numbers
  1. function validate_form(node) {
  2.     var val = true;
  3.  
  4.     // validation code sets the val that should be returned
  5.     // note the parameter node is a reference to your form already
  6.  
  7.     return val;
  8. }
  9.  
kind regards

Each record contains five fields, material_name, comp_sr_no, dept_sr_no, qtyl, wt.
And suppose there are three records. Now I want to check only material_name, if all the three records are filled with material_name. How can I check this? I don't know how to do this. I have tried to searched this solution on internet.

Thanks and regards,
Vikas
Jun 2 '08 #3
gits
5,390 Expert Mod 4TB
please post an example of your form since it would be a kind of guesswork without seeing what you have done so far ...

kind regards
Jun 2 '08 #4
vikas251074
198 100+
please post an example of your form since it would be a kind of guesswork without seeing what you have done so far ...

kind regards

OK Sir,

Should I provide code? If yes, then following is code.
Attached Files
File Type: txt mat.txt (4.7 KB, 329 views)
Jun 2 '08 #5
gits
5,390 Expert Mod 4TB
hmmm ...

try the following:

Expand|Select|Wrap|Line Numbers
  1. function validate_form(node) {
  2.     var val = true;
  3.  
  4.     // get the list of all 'mat'-fields
  5.     var list = node.getElementsByName('mat');
  6.  
  7.     for (var i = 0, n; n = list[i]; i++) {
  8.         // in case any value of a 'mat' field is empty we
  9.         // return false
  10.  
  11.         if (n.value == '') {
  12.             val = false;
  13.             break;
  14.         }
  15.     }
  16.  
  17.     return val;
  18. }
  19.  
kind regards
Jun 2 '08 #6
vikas251074
198 100+
I have added the above code as follows

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2. function validate_form(node) 
  3. {
  4.   var val = true;
  5.   // get the list of all 'mat'-fields
  6.   var list = node.getElementsByName('mat');
  7.   for (var i = 0; n = list[i]; i++) 
  8.   {
  9.     // in case any value of a 'mat' field is empty we return false
  10.     if (n.value == '') 
  11.     {
  12.       val = false;
  13.       break;
  14.     }
  15.   }
  16.   return val;
  17. }
  18. </script>

and modified the following line.

Expand|Select|Wrap|Line Numbers
  1. <form name="myform" action="smaterial.asp" method="post" onSubmit="return validate_form(this)">
Note:- action="smaterial.asp" is calling another file where message is displayed for submission of form i.e. 'Record has been saved.'

On running programme, form is submitted even without entering any value. Then I changed some line as follows -

Expand|Select|Wrap|Line Numbers
  1. function validate_form(node) 
  2. {
  3.   var val = true;
  4.   var n; 
  5.   // get the list of all 'mat'-fields
  6.   var list = node.getElementsByName('mat');
  7.   for (var i = 0; i < 3; i++) 
  8.   {
  9.     // in case any value of a 'mat' field is empty we
  10.     // return false
  11. alert("Form Submit Status");
  12.     n = list[i]
  13.     if (n.value == '') 
  14.     {
  15.       val = false;
  16.       break;
  17.     }
  18.   }
  19.   return val;
  20. }
But this is also not working. I think function validate_form(this) is not calling the function because alert message is also not displaying. How could I complete this job.

Thanks and regards,
Vikas
Jun 3 '08 #7
gits
5,390 Expert Mod 4TB
sorry my bad ... replace the node-reference with a document reference:

Expand|Select|Wrap|Line Numbers
  1. function validate_form() {
  2.     var val = true;
  3.  
  4.     // get the list of all 'mat'-fields
  5.     var list = document.getElementsByName('mat');
  6.  
  7.     for (var i = 0, n; n = list[i]; i++) {
  8.         // in case any value of a 'mat' field is empty we
  9.         // return false
  10.  
  11.         if (n.value == '') {
  12.             val = false;
  13.             break;
  14.         }
  15.     }
  16.  
  17.     return val;
  18. }
  19.  
kind regards

btw: don't use the language-attribute in script tags since it is deprecated ... use type:

[HTML]<script type="text/javascript">[/HTML]
and write onsubmit all in lowercase ...
Jun 3 '08 #8
vijay
30
I now creating material outpass for taking material out from our campus.
In the first page, persons name taking material out, issue_date, department, vehicle_no, driver_name, purpose, received_by and remarks is entered.
In the second page no. of materials to taken out is given.
In the third page, it creates no. of row as mentioned in the second page. suppose 5. Five row is created. Fields in this page are material_name, company_sr_no, department_sr_no, quantity, weight, remarks. Two buttons are there. One is 'Cancel' and other is form submit button 'Add'.

Here in third page, one problem regular occurs. When enter key is pressed by mistake without filling all details, the form is submitted (i.e. 'Add' button is pressed). How can I stop this? I want to there should be no effect of enter key without filling all the five row. If any one tries to click 'Add', 'Add' button should not work untill and unless all the five rows of material are filled.

Thanks and regards,
Vikas

use javascript functions to cary out validation..

call this function when the form is submited by using the event handler
onSubmit
Jun 3 '08 #9
gits
5,390 Expert Mod 4TB
use javascript functions to cary out validation..

call this function when the form is submited by using the event handler
onSubmit
as i said already: it is 'onsubmit' instead of 'onSubmit' ... it is a node attribute and all node-attributes should be written in lowercase and their values should be enclosed in double-quotes ... read post #8 -> this should work ...

kind regards
Jun 3 '08 #10
vikas251074
198 100+
Yes sir,

This problem has been solved now. This is working fine.

Thanks and regards,
Vikas
Jun 4 '08 #11
gits
5,390 Expert Mod 4TB
no problem ... post back to the forum anytime you have more questions ...

kind regards
Jun 4 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Glyphman | last post by:
I have a bunch of pages with long forms, with lots of input types-text, radios, textareas, and the debugging process has become overwhelming. What I need to happen is to make sure that 1. Every...
3
by: Kassam | last post by:
Hi MVPs out there. I have constructed an order form and the users will enter the informtion. I now need to send the filled out form as an e-mail (body being the HTML with the fille din data) to...
5
by: Codeman II | last post by:
Hi there, I am building a form where the user must upload a picture and fill in his details. Now I have a problem as all of this is on the same form. How will I be able to have the Browse...
4
by: Rick | last post by:
Hello, I'm having trouble with submitting my form when checking to see if data is present in the user-inputted fields. What I want to happen is for the user to input various pieces of data,...
3
by: Mike | last post by:
Hello: I was not able to find a regular ASP group, so I posted this here instead. I have a web app which is actually just ASP using VBScript as the server-side language, running on IIS6. ...
5
by: Navillus | last post by:
Hey gang, I have a login form that is empty by default, but can be filled with values from a previous form: <input type=text maxlength="40" size="40" name="user" value="`usr`"> <input...
7
by: GeorgeAtkins | last post by:
I want to create a web-based form or page that consists of a series of formatted questions and answers. The form will resemble an existing paper form. When the form is filled in, I want the user to...
2
by: Cerebral Believer | last post by:
Hi folks, Can anyone help me with this form: http://futurebydesign-music.com/_member/club_fbd_reg.php I have followed to coding instructions aas closely as I can, but I am getting errors...
11
by: V S Rawat | last post by:
using Javascript, I am opening a web-based url in a popup window. MyWin1=Window.Open(url, "mywindow") There is a form (form1) in the url in that popup window, I need to submit that form. ...
6
by: smk17 | last post by:
I've spent the last few minutes searching for this question and I found an answer, but it wasn't quite what the client wanted. I have a simple online form where the user needs to fill out five...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.