473,387 Members | 1,903 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
May 31 '08 #1
7 1533
DrBunchman
979 Expert 512MB
Hi Vikas,

You can use Javascript to validate your form after you've clicked your Add button and prevent it from submitting if certain conditions are not met.

Let's assume we have a form called TestForm with two textboxes and a submit button.
Expand|Select|Wrap|Line Numbers
  1.  <form name="TestForm" action="JS_Val.asp">
  2.   <input type="text" name="txt1" />
  3.   <input type="text" name="txt2" />
  4.   <input type="submit" value="Submit" OnClick="return Val();" />
  5.  </form>
  6.  
Notice that the submit button has an action defined for the OnClick event which means that when it is clicked the function Val() will be fired. It says "return Val();" which means the function is going to return a value telling the form whether to submit or not. Without that "return" the form would submit regardless of what we tell it to do. Here's an example of the Javascript function Val() which we could place between our head tags:
Expand|Select|Wrap|Line Numbers
  1. <head> 
  2. <script type="text/javascript">
  3.  {
  4.  var txt1 = document.TestForm.txt1.value;
  5.  var txt2 = document.TestForm.txt2.value;
  6.  if (txt1 == '')
  7.    {
  8.    return false;
  9.    }
  10.  if (txt2 =='')
  11.    {
  12.    return false;
  13.    }
  14.  } 
  15. </script>
  16. </head>
  17.  
Can you see what the code is doing? If either of the textboxes are blank then the function will return false to the submit button preventing it from continuing. Otherwise the function will return it's default value of true and your form will submit.

Let me know if this helps,

Dr B
Jun 2 '08 #2
vikas251074
198 100+
What coding if there is an array of records like as below.

Each record contains five fields, material_name, comp_sr_no, dept_sr_no, qty, 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
DrBunchman
979 Expert 512MB
Vikas,

The Javascript example I gave you above will validate the controls on your page so that your user cannot submit the form until they have filled in all the fields which you specified.

I don't understand what you mean 'an array of records'? Are you talking about database records? Is this a new question or does it relate to your original problem?

Please give code examples to explain your problem.

Dr B
Jun 2 '08 #4
vikas251074
198 100+
OK Sir, I am giving you code through attachment.


Thanks and regards,
Vikas
Attached Files
File Type: txt mat1.txt (4.7 KB, 325 views)
Jun 2 '08 #5
I have had this same problem on a form that i was using custom buttons for. And through days of research found out that pressing the "enter key" will bypass your validation.

You can run a javascript that will disable the enter key. Do a google search for more if this link doesn't help.

enter key

I hope this helps.

Jason
printedgoods.com
Jun 5 '08 #6
vikas251074
198 100+
Yes sir, this problem has been solved by using javascript method.

Thanks and regards,
Vikas
Jun 6 '08 #7
Jerry Winston
145 Expert 100+
I have had this same problem on a form that i was using custom buttons for. And through days of research found out that pressing the "enter key" will bypass your validation.

You can run a javascript that will disable the enter key. Do a google search for more if this link doesn't help.

enter key

I hope this helps.

Jason
printedgoods.com
printedgoods,

did you ever find a solution to your form submit/validation? If not heres one that works for me using FireFox or IE.

Expand|Select|Wrap|Line Numbers
  1. <form id='frmMyform' action='go.asp' method='post'>
  2.          <input type="text" id='txtFirstName'>
  3.          <input type="text" id='txtLastName'>
  4.          ...
  5.          <input type="button" onclick="getElementById('frmMyform').submit();">
  6. </form>
the reason this works is because you dont have a submit button in the form. the submit action can be triggered by pressing enter. By using a "button" type input element, there is no submit button to be triggered and the only way the form can be submitted is through the onclick action.
Jun 16 '08 #8

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: 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:
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.