| | |
Javascript Validation
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
Hello Good afternoon Guys
Iam KNR iam having a problem with javascript validation
i want to check validation of all controls at a time means
if i have a form with all fields blank then it has to show message
and if any of the field is filled then it dont have to show the message and
the message about blank field has to shown
please help me
Iam KNR iam having a problem with javascript validation
i want to check validation of all controls at a time means
if i have a form with all fields blank then it has to show message
and if any of the field is filled then it dont have to show the message and
the message about blank field has to shown
JavaScript Syntax (Toggle Plain Text)
if(trim(cname.value) == '') { alert('Enter a Name'); cname.focus(); return false; }
Last edited by peter_budo; Apr 25th, 2009 at 5:07 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
This demo will alert the user, depending on which is field is empty. Lets say for example, ( if field 1 is empty then, field 1 will be identified as invalid entry and as well as with the other field's also).
Don't worry--If you need a simple demo, im sure some other posters will provide another format of this code.
Hope it helps and good day to you...
Don't worry--If you need a simple demo, im sure some other posters will provide another format of this code.
Hope it helps and good day to you...
javascript Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <title>JavaScript Demo</title> <style id="internal" type="text/css"> /* <![CDATA[ */ label { display : block; margin : 0em 0em 1em 0em; } /* ]]> */ </style> <script type="text/javascript"> // <![CDATA[ var validate, showError; var i, x, invalidEntry, msg, error = []; showError = function( error ) { msg = "There were some problems...\n"; for ( i = 0; i < error.length; i++ ) { invalidEntry = i + 1; msg += "\n" + invalidEntry + ". " + error[i]; } alert( msg ); window.location.reload(); return; }; validate = function( form ) { form = ( document.getElementById ) ? document.getElementById("testform") : document.all.testform; if ( form ) { for ( var x = 1; x < form.elements.length; x++ ) { if ( eval("form.txt" + x + ".value.length") <= 0 ) { error[error.length] = "Field " + x + " requires a valid entry!"; } } if ( error.length > 0 ) { showError( error ); return false; } } alert("Thank you for visiting my site!"); return false; }; // ]]> </script> </head> <body> <div id="content"> <form id="testform" action="#" onsubmit="return validate( this );"> <div> <label for="txt1">Field 1: <input type="text" id="txt1" name="txt1" value="" size="20" /></label> <label for="txt2">Field 2: <input type="text" id="txt2" name="txt2" value="" size="20" /></label> <label for="txt3">Field 3: <input type="text" id="txt3" name="txt3" value="" size="20" /></label> <input type="submit" id="sbm" name="sbm" value="submit" /> </div> </form> </div> </body> </html>
Last edited by essential; Apr 25th, 2009 at 4:22 am.
![]() |
Similar Threads
- PHP: Form Validation (PHP)
- Javascript - Validation (JavaScript / DHTML / AJAX)
- Javascript Input Mask / Validation (JavaScript / DHTML / AJAX)
- problem with my radio button validation js (JavaScript / DHTML / AJAX)
- Dreamweaver php form validation and redirect (PHP)
- Simple checkbox validation question (JavaScript / DHTML / AJAX)
- javascript validation (JavaScript / DHTML / AJAX)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Ajax: auto refreshing a xml file load
- Next Thread: Two actions with one submit button ???
Views: 543 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
acid2 ajax ajaxexample ajaxhelp ajaxjspservlets array automatically autoplay beta blackjack boarder box button captcha card cart codes column css date debugger decimal design developer dom download element embed enter error events firefox flash focus form frameworks gears getselection google gwt hiddenvalue hint html htmlform ie7 iframe index java javascript javascripthelp2020 javascripts jawascriptruntimeerror jquery jsp libcurl listbox maps marquee masterpage media menu microsoft mimic mp4 offline onerror onmouseover parameters paypal php player position post problem programming prototype rating redirect safari scale scriptlets search security select size software sources starrating toggle tweet unicode validation variables w3c web webkit webservice window windowofwords xml





