473,394 Members | 1,739 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,394 software developers and data experts.

Validation

118 100+
I have a page with a form, the form has 3 text fields

"tireqty"

"oilqty"

-and-

"sparkqty"

and a button. The form action goes to a php page that I made, in which is validation, for whether or not the user inputted any data into each field.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if( $tireqty == "")
  3. {
  4.      echo "<script> alert ('You did not enter a number of tyres to order!'); history.go(-1); </script>";
  5. }
  6. else .....
  7.  
etc.. so it does each input field seperately

^ This is ok but not fool proof.

Would it be possible to add Javascript to the first page (with the form) so that when you press the button, or on the 'onchange' function for each input/text box, it'd check the value of the text fields to make they are in number format and get the value is existant, similar to the PHP code above.

Would that be possible and what code would I need?

Hope that was clear enough, if not tell me and I'll try and rephrase.

Thanks,
Sam
Sep 30 '07 #1
2 831
rpnew
188 100+
I have a page with a form, the form has 3 text fields

"tireqty"

"oilqty"

-and-

"sparkqty"

and a button. The form action goes to a php page that I made, in which is validation, for whether or not the user inputted any data into each field.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. if( $tireqty == "")
  3. {
  4.      echo "<script> alert ('You did not enter a number of tyres to order!'); history.go(-1); </script>";
  5. }
  6. else .....
  7.  
etc.. so it does each input field seperately

^ This is ok but not fool proof.

Would it be possible to add Javascript to the first page (with the form) so that when you press the button, or on the 'onchange' function for each input/text box, it'd check the value of the text fields to make they are in number format and get the value is existant, similar to the PHP code above.

Would that be possible and what code would I need?

Hope that was clear enough, if not tell me and I'll try and rephrase.

Thanks,
Sam

Hi Sam,

yes you can add the Javascript to work on with this in that way without submitting you can do validation.. if you are making a form then you can call this javascript function on form submit event or button click event or from whatever event you want from... just search on google and you'll get many examples regarding this....

RP
Oct 1 '07 #2
gits
5,390 Expert Mod 4TB
hi ...

of course you may add a javascript function to your page that validates the values of your fields on submit:

Expand|Select|Wrap|Line Numbers
  1. function validate_fields() {
  2.     var fields = { 'tireqty': 1, 'oilqty': 1, 'sparkqty': 1 };
  3.     var val = true;
  4.  
  5.     for (var i in fields) {
  6.         var field_value = document.getElementById(i).value;
  7.  
  8.         if (field_value === '' || isNaN(field_value)) {
  9.             val = false;
  10.             break;
  11.         }
  12.     }
  13.  
  14.     return val;
  15. }
and in your html you should have:

[HTML]<form name="whatever" onsubmit="return validate_fields();">[/HTML]
kind regards
Oct 1 '07 #3

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

Similar topics

21
by: Stefan Richter | last post by:
Hi, after coding for days on stupid form validations - Like: strings (min / max length), numbers(min / max value), money(min / max value), postcodes(min / max value), telefon numbers, email...
2
by: wumingshi | last post by:
Hi, When validating an XML instance, sometimes the schema is not enough to expression the validation rules. Additional validation rules may be expressed in an application-specific way. For...
4
by: Tim Meagher | last post by:
I am trying to use both validation controls and to add submit button attributes, but when I add the button attributes, the javascript fpr the validation controls is no longer created for the page. ...
14
by: Matt | last post by:
I want to know if ASP.NET Web Forms Validation Controls are Server-Side or Client-Side form validation? Since I think each validator control can select either 1) JavaScript based error dialog or 2)...
6
by: Stephen | last post by:
Hi, the validation controls dont work on Netscape or Mozilla and only on Internet Explorer why? How do i correct this problem? Thanks
7
by: Ryan Ternier | last post by:
We're running a site that has required field validation on the login page. It works fine on our development / test machines. However, when I upload this site to our live server i get this error. ...
5
by: Chris | last post by:
Based upon some prevoius postings on what to do for adding a 'add' row to a datagrid I utilize the footer to create the 'add' row. The only issue is that I have it sharing the 'UpDate_Command' and...
4
by: David Colliver | last post by:
Hi all, I am having a slight problem that hopefully, someone can help me fix. I have a form on a page. Many items on the form have validation controls attached. Also on this form are...
2
by: dustbort | last post by:
I recently had a problem where my required field validator stopped working. But, the page still posted back and tried to insert a record into the database without performing server-side validation....
6
by: Jon Paal | last post by:
validation doesn't fire what's missing ????? /////// ---- code -----/////////////////////////// Sub btnSubmit_Click(sender As Object, e As System.Web.UI.ImageClickEventArgs) 'Handles...
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: 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
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.