473,671 Members | 2,290 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Form validation still allows submission of empty fields

29 New Member
Hi.. guys
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.

Any clue?

Expand|Select|Wrap|Line Numbers
  1.  <html> 
  2. <head>
  3. <script language="JavaScript">
  4. function isEmpty(inputStr,fieldname){
  5. if (inputStr==null || inputStr==""){
  6. alert("please fill in the box")
  7. document.form1.fieldname.focus();
  8. document.form1.fieldname.select();
  9. return false;
  10. } else {
  11. return true;
  12. }
  13.  
  14. }
  15. </script> </head>
  16. <body>
  17. <form name="form1" method="GET" action=”?????????”>
  18. <p> User ID:
  19. <input type="text" name="txt1" onBlur="isEmpty(txt1.value,txt1.name)"/> 
  20. <br />
  21. <p> User Name:
  22. <input type="text" name="txt2" onBlur="isEmpty(txt2.value,txt2.name)"/>
  23. <br /> <br />
  24. <input type="submit" VALUE="SUBMIT" />
  25. </form> </body> </html>
  26.  
Mar 22 '07 #1
13 2620
Akhilesh1505
17 New Member
Hi.. guys
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.

Any clue?

<html>
<head>
<script language="JavaS cript">
function isEmpty(inputSt r,fieldname){
if (inputStr==null || inputStr==""){
alert("please fill in the box")
document.form1. fieldname.focus ();
document.form1. fieldname.selec t();
return false;
} else {
return true;
}

}
</script> </head>
<body>
<form name="form1" method="GET" action=”??????? ??”>
<p> User ID:
<input type="text" name="txt1" onBlur="isEmpty (txt1.value,txt 1.name)"/>
<br />
<p> User Name:
<input type="text" name="txt2" onBlur="isEmpty (txt2.value,txt 2.name)"/>
<br /> <br />
<input type="submit" VALUE="SUBMIT" />
</form> </body> </html>
You had given wrong
path in action=”??????? ??”
use like this action="".

Akhilesh
Mar 22 '07 #2
elsheh
29 New Member
Thanx
The problem is not because of the action attribute, you may eliminate it. The issue is how to prevent of submission empty fields. (got it?)
Cheers
You had given wrong
path in action=”??????? ??”
use like this action="".

Akhilesh
Mar 22 '07 #3
acoder
16,027 Recognized Expert Moderator MVP
Instead of passing the name, pass the object itself, e.g. txt1. Then in your function, in place of
Expand|Select|Wrap|Line Numbers
  1. document.form1.fieldname.focus()
you can have
Expand|Select|Wrap|Line Numbers
  1. fieldname.focus()
because fieldname is the text box object.
Mar 22 '07 #4
elsheh
29 New Member
thanx acoder

but still doesn't work properly.I mean, i still able to submit empty fields.
plz help

Instead of passing the name, pass the object itself, e.g. txt1. Then in your function, in place of
Expand|Select|Wrap|Line Numbers
  1. document.form1.fieldname.focus()
you can have
Expand|Select|Wrap|Line Numbers
  1. fieldname.focus()
because fieldname is the text box object.
Mar 22 '07 #5
iam_clint
1,208 Recognized Expert Top Contributor
[HTML]
<html>
<head>
<script language="JavaS cript">
function isEmpty(inputSt r,fieldname){
if (inputStr==null || inputStr==""){
alert("please fill in the box")
document.form1. fieldname.focus ();
document.form1. fieldname.selec t();
return false;
} else {
return true;
}
}
function validate() {
//check for blank input boxes here
//possibly alert("hey you didn't fill in everything"); and return false; if there is blank boxes (stops the submission);
//else return true
}
</script> </head>
<body>
<form name="form1" method="GET" onsubmit="valid ate();" action=”??????? ??”>
<p> User ID:
<input type="text" name="txt1" onBlur="isEmpty (txt1.value,txt 1.name)"/>
<br />
<p> User Name:
<input type="text" name="txt2" onBlur="isEmpty (txt2.value,txt 2.name)"/>
<br /> <br />
<input type="submit" VALUE="SUBMIT" />
</form> </body> </html>
[/HTML]

Changed title of thread to more suit the question being asked
Mar 22 '07 #6
Akhilesh1505
17 New Member
Hi.. guys
I’m trying to use JavaScript to validate my HTML for empty fields. My code is as below. The problem is that I can escape validation and submit empty fields.

Any clue?

<html>
<head>
<script language="JavaS cript">
function isEmpty(inputSt r,fieldname){
if (inputStr==null || inputStr==""){
alert("please fill in the box")
document.form1. fieldname.focus ();
document.form1. fieldname.selec t();
return false;
} else {
return true;
}

}
</script> </head>
<body>
<form name="form1" method="GET" action=”??????? ??”>
<p> User ID:
<input type="text" name="txt1" onBlur="isEmpty (txt1.value,txt 1.name)"/>
<br />
<p> User Name:
<input type="text" name="txt2" onBlur="isEmpty (txt2.value,txt 2.name)"/>
<br /> <br />
<input type="submit" VALUE="SUBMIT" />
</form> </body> </html>
you are doing validation on onBlur event of textbox,
If you want to validate on onSubmit event of form then
you need to do like this.
<form name="form1" method="GET" action=”??????? ??” onSubmit="valid ate()" >
and then make a validate() function in javascript.
Mar 23 '07 #7
Logician
210 New Member
you are doing validation on onBlur event of textbox,
If you want to validate on onSubmit event of form then
you need to do like this.
<form name="form1" method="GET" action=”??????? ??” onSubmit="valid ate()" >
and then make a validate() function in javascript.
Expand|Select|Wrap|Line Numbers
  1. <form name="form1" method="GET" action=”?????????” onSubmit="return  validate()" >
Mar 23 '07 #8
elsheh
29 New Member
how about parameters?
cheers
Expand|Select|Wrap|Line Numbers
  1. <form name="form1" method="GET" action=”?????????” onSubmit="return  validate()" >
Mar 23 '07 #9
acoder
16,027 Recognized Expert Moderator MVP
See this link.
Mar 23 '07 #10

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

Similar topics

6
4336
by: Charles Banas | last post by:
weird subject - i hope more than just one curious regular will hear me out. :) ok, i've got a bit of a big problem, and i need answers as soon as possible. i know this forum is meant for web developers, but is relevant discussion. i'm not OT here unless someone thinks i'm trolling (which i'm not, obviously). then i'll disappear and never show my face again. :P
4
2631
by: bnp | last post by:
Hi All, I am quite new the JavaScript. Basically I am a C++ programmer, but now I am working on JavaScript since last 5 days. I have a problem regarding the form validation. I have created a script that validates the form fields. the validation procedure is called ONCLICK event of the submit button. Follwowing is the structure of the validation procedure.
2
2363
by: Tim Mills | last post by:
The following code asks the user to sumbit a name, email address, and some text for a quotation via a FORM. I have written a javascript function to evaluate the fields in the form and pop-up a message to tell the user if all the fields have been fill-out. If the user has missed some information the form re-displays with red "alerts" indicating where the user have missed the information while re-populating the information the user has...
9
4168
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be honest I usually hire someone to do it for me, grab predone scripts and kind of hack out the parts that I need, or just do very minimal validation (e.g. this is numeric, this is alpha-numeric, etc.)
7
6988
by: h7qvnk7q001 | last post by:
I'm trying to implement a simple server-side form validation (No Javascript). If the user submits a form with errors, I want to redisplay the same form with the errors highlighted. Once the form is correct I need to submit to another page that uses the form data. I first tried making the form submit action= field point to the same file. When the form was correct, I tried loading the next page by using <META http-equiv refresh>. But...
27
4729
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
2
4262
by: ddog | last post by:
I have a form with 3 text fields (one of which is a zip code) and 5 combo boxes. The combo boxes are all set with the first value as 'selected' when the page is first displayed. The 3 text fields are required and are by default empty. I need to validate that the text fields have an entry and that the zip code is numeric and the correct length. If the form fails validation - one of the text fields is empty, for example - I need to alert...
7
3603
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
12
2484
by: Gustaf | last post by:
I've been working on a membership form for a while, and find it very tedious to get an acceptable level of form validation. A web search for solutions revealed some home-brewed solutions, such as these: http://simonwillison.net/2003/Jun/17/theHolyGrail/ http://samuelsjoberg.com/archive/2004/11/form-validation-on-client-and-server Quoting from the first link, this is my idea of what form validation is like from the user's perspective:
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8390
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6222
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
2048
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.