JavaScript - Problem In Zip Code Validation
Hello! There is something wrong in the code below. What is it? Can you help me please? The form validation was working just fine when I added the last 'if' for zip code validation. The function didn't work and returned true. The code is:
Code: <script type="text/javascript"> function validateForm() { var y=document.forms["form"]["firstname"].value; var f=document.forms["form"]["zipcode"].value; var x=document.forms["form"]["email"].value; var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (y==null || y=="NAME") { alert("First name must be filled out"); return false; } if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } } var re='/(^\d{5}$)/'; if (f!=re) { alert ("Not a valid address"); return false; } } </script> Any ideas or advice? Thank you in advance! Similar TutorialsI am trying to set up a looping structure that tests to see if the user enters a value. If the textbox is null then a global variable is false otherwise a checkbox is checked and the global variable is true. below is what i have done so far, please assist me. var isValid = false; window.onload = startForm; function startForm() { document.forms[0].firstName.focus(); document.forms[0].onsubmit = checkEntries; alert("You have been added to the list") } function checkEntries() { var menus = new Array(); var formObject = document.getElementsByTagName('*'); for (var i=0; i < formObject.length; i++){ if (formObject[i] == "myform") menus.push(formObject[i]); if (document.forms[0].firstName.value.length==0 || document.forms[0].firstName.value.length == null){ isValid= false; alert("Please enter a first name"); } else (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].lastName=="" || document.forms[0].lastName== null){ alert("Please enter a last name"); isValid = false; } else (document.forms[0].check1.checked=true); isValid=true; if (document.forms[0].email=="" || document.forms[0].email== null) { alert("Please enter a valid email"); } else return (document.forms[0].check0.checked=true); isValid=true; if (document.forms[0].bDate=="" || document.forms[0].bDate== null) { isValid=false; alert("please make sure you enter a valid birth date."); } else (document.forms[0].check0.checked=true); isValid=true; } } here is the form html... <form name="myform" > <input type="checkbox" name="check0" class="check0" id="check0" > First: <input type="text" name="firstName" id="firstName"> <BR> <input type="checkbox" name="check1" class="check1" id="check1" > Last: <input type="text" name="lastName" id="lastName" ><BR> <input type="checkbox" name="check2" class="check2" id="check2" > E-Mail: <input type="text" name="email" id="email"> <BR> <input type="checkbox" name="check3" class="check3" id="check3" > Birthday (mm/dd/yyyy): <input type="text" name="bDate" id="bDate"> <BR> <input type="submit" value="Join our mailing List" /> </form> I'd like to add validation for 5 digits (numbers only) to this code: if($("#newvalue1").val() == "" && operator == "Equals" || $("#newvalue2").val() == "" && operator == "Range" ){ good = false; alert("5 digits please."); I have tried the code below, but it's not working. Could anyone help, please? Thanks! if($("#newvalue1").val() == "" && operator == "Equals" || $("#newvalue2").val() == "" && operator == "Range" || $("#newvalue2").val() !/^\d{5} && operator == "Range" ){ good = false; alert("5 digits please."); Hi, I've been helped out and given a great code for part of the validation, the problem is I have tried to adapt it on subsequent fields and my validation has stopped working. I am including the email validation which works and then confirm email, select sex and select year of birth, none of the latter three work. I would be extremely grateful for any assistance as I am completely stuck. Code: <html> <head> <script type="text/javascript"> function check(form){ var email=form.email; if(!(/^([a-z0-9])([\w\.\-\+])+([a-z0-9])\@((\w)([\w\-]?)+\.)+([a-z]{2,4})$/i.test(email.value))){ form.email.value=""; alert("Please enter a valid email!"); myfield = email; setTimeout('myfield.focus();myfield.select();' , 10); return false; } var cemail=form.cemail; var cemailv=form.cemail.value; form.cemail.value=cemailv; if(!cemailv =="emailv") { form.pword.value=""; alert("Your email entries do not match!"); myfield = ln; setTimeout('myfield.focus();myfield.select();' , 10); return false; } var msex=form.msex; var msexv=form.msex.value; var fsex=form.fsex; var fsexv=form.fsex.value; if ((msexv==0 && fsexv==0)||(msexv=="" && fsexv=="")){ alert("Please select your sex!"); return false; } var DOBYear=form.DOBYear; if((var DOBYear==0)&&(varDOBYear>1993)){ alert("You have either not selected a year of birth or are not over eighteen years old!"); myfield = DOBYear; setTimeout('myfield.focus();myfield.select();' , 10); return false; } return true; } </script> </head> <body> <form action="guestdetails.php" name="form" onsubmit="return check(this)" method="post"> <fieldset class="two"> <legend>Your Information:</legend> <br /> <label class="two">Email:</label> <input type="text" class="input" name="email" value="enter email address" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'enter email address':this.value;" size="30%" /> <br /> <br /> <label class="two">Confirm Email:</label> <input type="text" class="input" name="cemail" value="confirm email address" onclick="this.value='';" onfocus="this.select()" onblur="this.value=!this.value?'confirm email address':this.value;" size="30%" /> <br /> <br /> <label class="two">Sex:</label> <br /> <label class="two">Male</label> <input type="radio" name="msex" value="male" onclick="1" /> <br /> <label class="two">Female</label> <input type="radio" name="fsex" value="female" onclick="1" > <br /> <br /> <select name="DoBYear" class="input"> <option value="0" selected"selected">Year</option> <option value="2009">2009</option> <option value="2008">2008</option> <option value="2007">2007</option> <option value="2006">2006</option> <option value="2005">2005</option> <option value="2004">2004</option> <option value="2003">2003</option> <option value="2002">2002</option> <option value="2001">2001</option> <option value="2000">2000</option> <option value="1999">1999</option> <option value="1998">1998</option> <option value="1997">1997</option> <option value="1996">1996</option> <option value="1995">1995</option> <option value="1994">1994</option> <option value="1993">1993</option> <option value="1992">1992</option> <option value="1991">1991</option> <option value="1990">1990</option> <option value="1989">1989</option> <option value="1988">1988</option> <option value="1987">1987</option> <option value="1986">1986</option> <option value="1985">1985</option> <option value="1984">1984</option> <option value="1983">1983</option> <option value="1982">1982</option> <option value="1981">1981</option> <option value="1980">1980</option> <option value="1979">1979</option> <option value="1978">1978</option> <option value="1977">1977</option> <option value="1976">1976</option> <option value="1975">1975</option> <option value="1974">1974</option> <option value="1973">1973</option> <option value="1972">1972</option> <option value="1971">1971</option> <option value="1970">1970</option> <option value="1969">1969</option> <option value="1968">1968</option> <option value="1967">1967</option> <option value="1966">1966</option> <option value="1965">1965</option> <option value="1964">1964</option> <option value="1963">1963</option> <option value="1962">1962</option> <option value="1961">1961</option> <option value="1960">1960</option> <option value="1959">1959</option> <option value="1958">1958</option> <option value="1957">1957</option> <option value="1956">1956</option> <option value="1955">1955</option> <option value="1954">1954</option> <option value="1953">1953</option> <option value="1952">1952</option> <option value="1951">1951</option> <option value="1950">1950</option> <option value="1949">1949</option> <option value="1948">1948</option> <option value="1947">1947</option> <option value="1946">1946</option> <option value="1945">1945</option> <option value="1944">1944</option> <option value="1943">1943</option> <option value="1942">1942</option> <option value="1941">1941</option> <option value="1940">1940</option> <option value="1939">1939</option> <option value="1938">1938</option> <option value="1937">1937</option> <option value="1936">1936</option> <option value="1935">1935</option> <option value="1934">1934</option> <option value="1933">1933</option> <option value="1932">1932</option> <option value="1931">1931</option> <option value="1930">1930</option> <option value="1929">1929</option> <option value="1928">1928</option> <option value="1927">1927</option> <option value="1926">1926</option> <option value="1925">1925</option> <option value="1924">1924</option> <option value="1923">1923</option> <option value="1922">1922</option> <option value="1921">1921</option> <option value="1920">1920</option> <option value="1919">1919</option> <option value="1918">1918</option> <option value="1917">1917</option> <option value="1916">1916</option> <option value="1915">1915</option> <option value="1914">1914</option> <option value="1913">1913</option> <option value="1912">1912</option> <option value="1911">1911</option> <option value="1910">1910</option> <option value="1909">1909</option> <option value="1908">1908</option> <option value="1907">1907</option> <option value="1906">1906</option> <option value="1905">1905</option> <option value="1904">1904</option> <option value="1903">1903</option> <option value="1902">1902</option> <option value="1901">1901</option> </select> <br /> <br /> <br /> </fieldset> <br /> <br /> <input type="submit" value="Submit"/> </form> <br /> <br /> </body> </html> Hello Everyone I am new on java script and I want to check the form blank text fields by using onChange event. Please guide me, is it possible or not....If possible then please send me the code. MY EMAILID IS dhiman.anurag1@gmail.com ........ THANK YOU hi, i need US zip code formatting on my page. as zip code can be 5 digits or 5-4 digits, our requirement is that when user types in 6th digit, hyphen automatically gets added between 5th and 6th digit. ex: user enters 100161,it should become formatted as 10016-1 and then user can continue to add rest of digits. pls advice, highly appreciate. thanks I need help with a JavaScript form validation code. I am using the form validation code that is found on this page: http://www.dynamicdrive.com/dynamici...uiredcheck.htm The code works fine for me, but what I'm trying to do is add an additional condition to it. Currently, I just have the code set up to check if the user has enter their name, email, and phone number. But I also need it to validate something else only if a specific condition is true. On my form I have 2 different sets of Radio lists. One is called Function and the other radio list is called Design. If the user selects an option on one of the 2 lists, then it will be required for the user to also select an option from the 2nd list. The user CAN decide not to select anything from either radio list, but can not select from one list and NOT from the other. This is the If statement that I created (don't know if its correct or how to insert it to my current validation code). Code: <script type="text/javascript"> if (Function+Design<1 or == 400 or == 800) {document.write("Please select both a Function and Design Type");} </script> hello i have a form which when the user hits "submit," the info in the textboxes is entered to a database. the only textbox which is not entered to the DB is an "age" textbox, which i need to verify to see if user is 18yrs or older. if user is not 18 years or older, they get an alert telling them they arent 18+. if they are, then the form submits this is my code so far, and i dont get any alerts when i enter an age younger than 18: Code: <head> <script language="text/javascript"> var age; document.getElementById("userage").value = age; if (age >=18) document.location="feedbacksaveanddisplay.php"; else { alert('Sorry, we can not let you in!') document.location="content.html"; } </script> </head> <form method = "post" action = "FeedbackSaveAndDisplay.php"> <input type = "hidden" name = "user" value = "test"/> <input type = "hidden" name = "pwd" value = "test"/> <p>Enter your name, feedback, score</p> <table> <tr> <td>Name</td> <td> <input type = "text" name = "name" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Feedback</td> <td> <input type = "text" name = "feedback" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Score</td> <td> <input type = "text" name = "score" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Product</td> <td> <input type = "text" name = "product" style="width:150px; height:20px;" /> </td> </tr> <tr> <td>Age</td> <td> <input type = "text" name = "age" style="width:150px; height:20px;" /> </td> </tr> <tr> <td colspan = "2"> <input type = "submit" value = "Submit" /> </td> </tr> </table> </form> any tips/advice on how to fix my code? the problem i think is in the javascript... will greatly appreciate any help thanks!! I am trying to use some JavaScript code that I found by searching the web, my goal is to have a form with a "required" checkbox to force my users to acknowledge they have read my "Terms and Conditions" section. The code that I found ALMOST works properly - it does pop-up the "Alert" window when the checkbox is blank and the submit button is clicked... however, if the user closes the Alert window in order to click the checkbox in compliance, the "submit.form" command is executed before they have a chance. In other words, there is no "pause" in the execution of the script to allow the user to make the correction by clicking the checkbox. Here is the code: Code: <script LANGUAGE="JavaScript"> <!-- function ValidateForm(form){ ErrorText= ""; if ( form.terms.checked == false ) { alert ( "Please check the Terms & Conditions box." ); return false; } if (ErrorText= "") { form.submit() }} --> </script> Here is the HTML for the checkbox: Code: <input name="terms" type="checkbox" value="Yes" /> Here is the HTML for the submit button that calls the function: Code: <input type="submit" value="Continue" onclick="ValidateForm(this.form)" /> I've searched for other examples of code to accomplish this objective, but I'm hoping for a quicker solution by coming to the experts who can see the flaw in this JavaScript. Thanks for any help, Rob Hi guys, I am working on my first validation form and although the Submit button works fine and puts me to the landing page, I don't get the alert, when nothing is checked. Please look at my code and help if you can. I really don't need anything fancy, just working Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta name="keywords" content="social media survey, social media, media survey, survey, danish media, danish media survey" /> <meta name="description" content="This survey is a school project, not an actual research. It has been designed to figure out the connection between the gender of the Danish users and their knowledge and usage of social media." /> <script language="JavaScript" type="text/javascript"></script> <script> function isRadioButtonSelected(radioGrpName, errorMsg){ var radios = document.getElementsByName(radioGrpName); var i; for (i=0; i<radios.length; i=i+1 ){ if (radios[i].checked){ return true; } } alert(errorMsg); return false; } function validate(){ if(isRadioButtonSelected('gender', 'please select your gender')){ return true; } return false; } </script> <title>The Social Media survey</title> <style type="text/css"> <!-- body { font: 100%/1.4 Verdana, Arial, Helvetica, sans-serif; background: #8DC63F; margin: 0; padding: 0; color: #000; } } a img { border: none; } .container { width: 960px; margin: 0 auto; } .header { background: #FFF; margin-top: 30px; background-color:transparent; background-image:url(header.jpg); background-attachment: fixed; background-position:left center; background-repeat:no-repeat; } .content { padding-left: 50px; padding-right: 50px; padding-top: 30px; padding-bottom: 30px; background-color:#E7EFB9; font-family:Verdana, Geneva, sans-serif; font-size: 13px; } .footer { background: #FFF; } .fltrt { float: right; margin-left: 8px; } .fltlft { float: left; margin-right: 8px; } .clearfloat { clear:both; height:0; font-size: 1px; line-height: 0px; } </style> </head> <body> <div class="container"> <div class="header"><img src="header1.jpg" alt="The Social Media survey" width="960" height="175" /></div> <div class="content"> <form id="page1" action="http://projects.knord.dk/interaction/saveforminfo.aspx" onsubmit="return validate(); method="post"> <input type="hidden" name="surveyid" value="igakotra" /> <input type="hidden" name="landingpage" value="http://www.google.com" /> <input type="hidden" name="usecookie" value="true" /> <h3>1. Choose your gender</h3> <input type="radio" name="gender" value="male" id="male"/><label for "male">Male</label> <input type="radio" name="gender" value="female" id="female"/><label for "female">Female</label><br /><br /> <input type="submit" name="submit" value="Submit"/> </form> </div> <div class="footer"><a href="page1.html"><img src="1page.jpg" width="960" height="99" alt="1/6 pages" /></div> </div> </body> </html> I really need it asap... thanks guys, you're awesome Working on college assignment, cant figure it out and need help! Basically a form that asks the user to fill in a valid email and password (ill give them the password), doesnt matter if it isnt secure, or if the email accepts dodgy emails (im just verifying the @ and a . and that is ok for the purpose of this. Anyway been trying with this code for ages now and cant see what is wrong but it isnt working, ive swapped it around and at times it does check that it is a valid email, sometimes it allows empty inputs. here is the code <script type="text/javascript"> function validateForm() { var x=document.forms["myForm"]["email"].value var y=document.forms["myForm"]["password"].value var atpos=x.indexOf("@"); var dotpos=x.lastIndexOf("."); if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length) { alert("Not a valid e-mail address"); return false; } </script> I think i need something like && (y!="123") around the 'if' statement, but not a clue how or where it goes. Basically im going to set the password to 123 so dont have to allow for caps etc. Easiest way to do this, anyone plleeeeeaaasseee?? Kind regards Alan here is the html code that i have PHP Code: <td valign="middle" valign="middle"> <input type="radio" name="gender" id="genderM" value="Male" /> Male <input type="radio" name="gender" id="genderFM" value="Female" /> Female </td> and here is the js funtion PHP Code: var $j = jQuery.noConflict(); function isValidEmail(str) { return (str.indexOf(".") > 2) && (str.indexOf("@") > 0); } function validateForm(){ var firstName; var lastName; var email; var mobile; var comment; var error; firstName = $j('#firstName').val(); lastName = $j('#lastName').val(); email = $j('#email').val(); mobile = $j('#mobile').val(); comment = $j('#comment').val(); if(firstName=='' || firstName.length < 3){ error = 'Please Enter Your First Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(lastName=='' || lastName.length < 3){ error = 'Please Enter Your Second Name'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } //mob //$jmob_pattern = '^\d{10}$j'; if(mobile.length != 10 || isNaN(mobile)){ error = 'Please Enter Your Mobile Number'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(email=='' || !isValidEmail(email)){ error = 'Please Enter Your Email Address'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } if(comment.length < 5){ error = 'Please Enter A Comment'; $j('#errormsg').html('<p class="errors">'+ error +'</p>'); return false; } return true; } Does anybody know how i check to see if the radio button is select and also can anybody tell me how i can check for an email in the correct format the function isValidEmail in the above alows emails to pass through if they are in this format aaa@aaa. i only want them to go through if they are aaa@aaa.com Thanks for your help if you give it Hi, I have got a validation problem in my javascript. The user needs to enter into "city" text box and also to select a state from a drop down list. The problem is that the function "checkValue" goes into the loop. Can anybody pinpoint the problem? Code: <INPUT TYPE='text' NAME='city' size='50' maxlength='50' id="City" onBlur="return checkValue(this),onchange= compLoop <select name='state' class='dropdown' id="State" onblur="return checkValue(this),onchange= compLoop()"> <option selected value=''>Select a State <option value="AL">Alabama <option value="AK">Alaska <option value="AZ">Arizona <option value="AR">Arkansas <option value="CA">California </select> <INPUT TYPE='text' NAME='zip' size='10'maxlength='10' id="Zip" onBlur="return checkValue(this),onchange= compLoop()"> This is the function checkValue() Code: function checkValue(textbox) { if(textbox.value==""||textbox.value==null) { alert("Please enter the value for "+ textbox.id); textbox.style.background='pink'; textbox.focus(); return false; } else { textbox.style.background='white'; return true; } } Hi all, I have some problem about validating my form.Infact nothing is happening when clicking the submit button.Can anyone tell me where the problem is.Here are my code. Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create New Customer-PAXWine</title> <style type="text/css"> <!-- body { margin:0 px; padding:0px; } #container { clear: both; float: none; height: 800px; width: 970px; margin-right: auto; margin-left: auto; } #content { background-color: #BC9C85; height: 800px; width: 970px; } #content-title{ padding: 25px 5px 5px 25px; color:#521514; font-family: Arial, "Times New Roman", Times, serif; font-size:10px; } #fieldset{ border:4px solid #E8E4CB; -moz-border-radius:10px; -webkit-border-radius:10px; border-radius:10px; background:#FCFCF9; width:700px; padding:22px 25px 12px 33px; margin:28px; } #legend{ float:left; font-weight:normal; font-size:15px; border:1px solid #fefefe; background:#521514; color:#fff; margin: -33px 0 0 -10px; padding:2px 8px; position:relative; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; display:inherit } #buttons{ margin:25px 370px; } --> </style> <script type="text/javascript"> function echeck(str) { var at = "@" var dot = "." var lat = str.indexOf(at) var lstr = str.length var ldot = str.indexOf(dot) if (str.indexOf(at)==-1) { alert("Invalid E-mail ID") return false; } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) { alert("Invalid E-mail ID") return false; } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) { alert("Invalid E-mail ID") return false; } if (str.indexOf(at,(lat+1))!=-1) { alert("Invalid E-mail ID") return false; } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) { alert("Invalid E-mail ID") return false; } if (str.indexOf(dot,(lat+2))==-1) { alert("Invalid E-mail ID") return false; } if (str.indexOf(" ")!=-1) { alert("Invalid E-mail ID") return false; } return true; } //checkbox function function DoTheCheck() { message = "Your Preference:\n\n" //For each checkbox see if it has been checked, record the value. for (i = 0; i < document.myform.wine.length; i++) if (document.myform.wine[i].checked) { message = message +document.myform.wine[i].value + "\n" } alert(message) } //Created / Generates the captcha function function DrawCaptcha() { var a = Math.ceil(Math.random() * 10)+ ''; var b = Math.ceil(Math.random() * 10)+ ''; var c = Math.ceil(Math.random() * 10)+ ''; var d = Math.ceil(Math.random() * 10)+ ''; var e = Math.ceil(Math.random() * 10)+ ''; var f = Math.ceil(Math.random() * 10)+ ''; var g = Math.ceil(Math.random() * 10)+ ''; var code = a + ' ' + b + ' ' + ' ' + c + ' ' + d + ' ' + e + ' '+ f + ' ' + g; document.myform.txtCaptcha.value = code } // Remove the spaces from the entered and generated code function removeSpaces(string) { return string.split(' ').join(''); } function validateform() { var nic = document.myform.nic.value; var firstname = document.myform.fname.value; var surname = document.myform.sname.value; var phone = document.myform.phone.value; var mail = document.myform.mail.value; var chks = document.getElementsByName('wine[]'); var hasChecked = false; var username = document.myform.uname.value var pass1 = document.myform.pass1.value; var pass2 = document.myform.pass2.value; var str1 = document.myform.txtCaptcha.value; var str2 = document.myform.txtInput.value; var which = document.myform.fname.value; var which1 = document.myform.sname.value; var numericExpression = /^[0-9]+$/; var message = document.getElementById('confirmMessage'); var returnval=false; if (nic.value == "") { window.alert("Please enter your National Identity Card Number."); nic.focus(); return false; } if (firstname.value == "") { window.alert("Please enter your First Name."); fname.focus(); return false; } if (/[^a-z]/gi.test(which.value)) { alert ("Only Alphabets Are Valid In This Field"); which.value = ""; which.focus(); return false; } if (surname.value == "") { window.alert("Please enter your Last Name."); sname.focus(); return false; } if (/[^a-z]/gi.test(which1.value)) { alert ("Only Alphabets Are Valid In This Field"); which1.value = ""; which1.focus(); return false; } if (phone.value == "") { window.alert("Please enter your Phone Number."); phone.focus(); return false; } if (!phone.value.match(numericExpression)) { alert("Phone Number Must Consists of Only Numbers"); phone.focus(); return false; } if (phone.value.length != 7) { alert("Phone number must consist of 7 numbers"); phone.focus(); return false; } if (mail.value == "") { alert("Please Enter your Email Address") mail.focus() return false } if (echeck(mail.value)==false) { mail.value="" mail.focus() return false; } if (chks.length[i].checked) { hasChecked = true; break; } if (hasChecked == false) { alert("Please select at least one preference."); return false; } if (username.value == "") { window.alert("Please enter a username."); uname.focus(); return false; } if (username.value.length < 8) { window.alert("Username must consists of more than 8 character."); uname.focus(); return false; } if (pass1.value == "") { window.alert("Please enter A Password."); pass1.focus(); return false; } if (pass2.value == "") { window.alert("Please Re-enter the password."); pass2.focus(); return false; } if (pass1.value != pass2.value) { window.alert("You did not enter the same password twice. Please re-enter both now."); pass1.focus(); pass1.select(); return false; } if (removeSpaces(str1.value) != removeSpaces(str2.value)) { windows.alert("The registration code did not match the one displayed.Please re-enter the code"); txtInput.focus(); return false; } return window.alert('Registration was Successfull'); } function allowReset() { return window.confirm('Do you really want to clear this form?') } </script> </head> <body> <div id="container"> <div id="content"> <div id="content-title"> <h1>Create an Account</h1> </div> <div id="fieldset"> <div id="legend">Personal Information</div> <form name="myform" action="" onSubmit = "return validateform();" onReset = "return allowReset()" method = "post" action = ""> <table> <tr> <td>NIC:</td> <td><input type="text" id="nic" name="nic" value="" size="15"></td> </tr> <tr> <td>First Name:</td> <td><input type="text" id="fname" name="fname" value="" size="15"></td> </tr> <tr> <td>Surname:</td> <td><input type="text" id="sname" name="sname" value="" size="15"></td> </tr> <tr> <td>Phone:</td> <td><input type="text" id="phone" name="phone" value="" size="15"></td> </tr> <tr> <td>Email address:</td> <td><input type="text" id="mail" name="mail" value="" size="15"></td> </tr> <tr> <td>Preference:</td> <td> <input type="checkbox" name="wine" value="White wine" onclick="DoTheCheck();"/>White wine <input type="checkbox" name="wine" value="Red wine" onclick="DoTheCheck();"/>Red wine <input type="checkbox" name="wine" value="Rose wine" onclick="DoTheCheck();"/>Rose wine </td> </tr> <tr> <td>Sex:</td> <td> <input type="radio" id="sex" value="Male" checked>Male <input type="radio" id="sex" value="Female">Female </td> </tr> <tr> <td>Country:</td> <td> <select name="country"> <option value="none">Select Country</option> <option value="Algeria">Algeria</option> <option value="Argentina">Argentina</option> <option value="Australia">Australia</option> <option value="Bahamas">Bahamas</option> <option value="Brazil">Brazil</option> <option value="Brunei">Brunei</option> <option value="Canada">Canada</option> <option value="China">China</option> <option value="Costa Rica">Costa Rica</option> <option value="Finland">Finland</option> <option value="France">France</option> <option value="Hungary">Hungary</option> <option value="India">India</option> <option value="Indonesia">Indonesia</option> <option value="Italy">Italy</option> <option value="Madagascar">Madagascar</option> <option value="Malaysia">Malaysia</option> <option value="Mauritania">Mauritania</option> <option value="Mauritius">Mauritius</option> <option value="Mexico">Mexico</option> <option value="Netherlands">Mexico</option> <option value="New Zealand">New Zealand</option> <option value="Poland">Poland</option> <option value="Portugal">Portugal</option> <option value="Romania">Romania</option> <option value="Rwanda">Rwanda</option> <option value="Seychelles">Seychelles</option> <option value="Singapore">Singapore</option> <option value="Slovakia">Slovakia</option> <option value="South Africa">South Africa</option> <option value="Spain">Spain</option> <option value="Taiwan">Taiwan</option> <option value="Thailand">Thailand</option> <option value="Tunis">Tunis</option> <option value="United Kingdom">United Kingdom</option> <option value="United States">United States</option> <option value="Uruguay">Uruguay</option> <option value="Vanuatu">Vanuatu</option> <option value="Vatican City">Vatican City</option> <option value="Venezuela">Venezuela</option> <option value="Yemen">Yemen</option> <option value="Zambia">Zambia</option> <option value="Zimbabwe">Zimbabwe</option> </select> </td> </tr> <tr> <td>Username:</td> <td><input type="text" id="uname" name="uname" value="" size="15" ></td> </tr> </table> </div> <div id="fieldset"> <div id="legend">Login Information</div> <table> <tr> <td>Password:</td> <td><input type="password" id="pass1" name="pass1" value="" size="15" /></td> <td> </td> <td>Confirm Password:</td> <td><input type="password" id="pass2" value="" size="15" /></td> </tr> </table> </div> <div id="fieldset"> <div id="legend">Capcha</div> <table> <tr> <td> <input type="text" id="txtCaptcha" style="text-align:center; border:none;font-weight:bold; font-family:Modern"/> </td> </tr> <tr> <td> <input type="text" id="txtInput"/> </td> </tr> <tr> <td> <input type="button" id="btnrefresh" value="Refresh" onclick="DrawCaptcha();" /> </td> </tr> </table> </div> <div id="buttons"> <input type="submit" value="Submit" /> <input type="reset" value="Reset"/> </div> </form> </div> </div> </body> </html> hi again i hope somebody will help me to fix this problem I have a form which has not submit button but two options either to pay or to just submit so i use this in my code: Code: td><input type="button" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" /> <input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td> so when they click on "Payments" they move to "payments.php and when they click on "More Information" they move to confirmation.php. Now my problem is i wants to validated it either through JavaScript or PHP but there is only one way i know with submit method. here i am using onClick function to move to other page. Please if somebody can help i much appericiate. here is the complete code of form i try to use PHP validation here but no luck please help me Code: <?php if ($_POST['submit']) { $title = $_POST['title']; $name = $_POST['name']; $insurance = $_POST['insurance']; $address = $_POST['address']; $phone = $_POST['phone']; $email = $_POST['title']; $error = ""; if (!$title) $error = $error. "Title <br />"; if (!$name) $error = $error. "Name <br />"; if (!$insurance) $error = $error. "National Insurance Number <br />"; if (!$address) $error = $error. "Address <br />"; if (!$phone) $error = $error. "Telephone Number <br />"; if (!$email) $error = $error. "Email Address <br />"; if (!$error !="") echo "Please Fill in The Following Required Fields <br /> $error"; else { return $_POST['submit']; } } ?> <div id="form" style="margin: 90px;"> <form action="" method="POST"> <table> <tr> <td align="right"> Title:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="title"> </td> </tr> <tr> <td align="right"> Name:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="name"> </td> </tr> <tr> <td align="right"> National Insurance<br /> Number:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="insurance"> </td> </tr> <tr> <td align="right"> Address:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="address"> </td> </tr> <tr> <td align="right"> Tleephone Number:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="phone"> </td> </tr> <tr> <td align="right"> Email:<span style="color:red;">*</span> </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="email"> </td> </tr> <tr> <td align="right"> CSCS Registration Number: </td> <td> <input style="border:1px solid #4088b8;" type="text" size="29" name="registration"> </td> </tr> <tr> <td align="right"> Special Accommodations: </td> <td> <textarea style="border:1px solid #4088b8;" type="textarea" cols="30" rows="5" name="comments"> </textarea> </td> </tr> <tr><td> </td></tr> <tr><td> </td> <td><input type="button" value="Payment" onClick="this.form.action='payments.php';this.form.submit()" /> <input type="button" value="More Information" onClick="this.form.action='confirmation.php';this.form.submit()" /></td> </tr> </table> </form> </div> Hi, I am having problem in validating my form using spry tools. The problem is that if I try to include any other validation other than spry along with spry validation the spry validation does not work. Plzz tell a possible solution I use this javascript validation in my form.. http://www.tizag.com/javascriptT/javascriptform.php but without validation values go to database.. Can anyone guide me how to solve this? First i import javascript file like this.. <script type="text/javascript" src="validate.js"></script> Part of the My code goes like this.... PHP Code: <form action="Process_reg.php" method="post" name="reg" id="reg" onsubmit="return formValidator()"> <div id="accordion" style="width:400px; height:500px; font-size:12px; font-family:Arial, Helvetica, sans-serif"> <h3><a href="#">General Details</a></h3> <div> <table cellpadding="5px" cellspacing="5px"> <tr> <td>First name</td> <td><input type="text" name="fname" id="fname" size="20px" title="Must be at least 8 characters." /></td> </tr> I just only try o validate email field only... email field goes like this PHP Code: <tr> <td>Email</td> <td><input type="text" name="email" id="email" size="20px" title="Enter Valid Email Address" /></td> </tr> My whole code attach here... Click here to download Thanks I have an issue with a form I am creating, I have many check boxs where at least one of the 2 needs to be selected and the final one has to be selected for the submit button to become active Code: <form id="form1" action="#" method="post"> One <input type="checkbox" name="value1" onMouseDown='submit_form()'/> Two<input type="checkbox" name="value2" onMouseDown='submit_form()'/> //atleast 1 of these 2 has to be selected Three<input type="checkbox" name="value3" onMouseDown='submit_form()'/> //this 1 has to be selected <input type="submit" name="submit" value="submit" id="submit" disabled="disabled"/> this is the javascript I have atm to do this Code: function submit_form(){ if (form1.value1.checked == false || form1.value2.checked == false) { document.getElementById(submit); orderForm.submit.disabled=false; } } i cant seem to get this to work, forgetting about the 3rd checkbox for now any help would be greatly appreciated! Hi folks this is my first post Edit: sorry for the incorrect title should have read simple javascript validation problem! i have a fair understanding of php and mysql and have never had to use javascript as i was secretly trying to avoid it. The time has now come where i want to use it for client side validation on a form. I am able to validate most of fields however i need to validate a date to check it has been entered in the following format dd/mm/yyyy and that the date is not greater than todays date. N.B the date is entered into a text field in HTML i wrote a function with lots of if/else statements and failed. Im 100% positive there is a far simpler way to achieve my goal any help would be greatly appreciated. Thanks Code: function checkDate(elem, helperMsg){ var day = elem.substr(0,2); var month = elem.substr(3,2); var year = elem.substr(6,4); if(day < 01 || day > 31) { var invalidday = true; } if (month < 0 || month > 12) { var invalidmonth = true; } if (year < 01 || year > 2099) { var invalidyear = true; } if ( month==04 || month==06 || month==09|| month==11) { if (day == 31) { var invalidday = true; } } if (month==02) { if (day > 28) { var invalidday = true; } } if (invalidday || invalidmonth || invalidyear) { alert(helperMsg); elem.focus(); return false; } else { var dd = today.getDate(); var mm = today.getMonth()+1;//January is 0! var yyyy = today.getFullYear(); if(dd < 10) { dd='0'+dd; } if(mm < 10) { mm='0'+mm; } } if (day > dd && month > mm && year > yyyy) { alert(helperMsg); elem.focus(); return false; } else { return true; } } Working of JS form validation now, this is my code: Code: <html> <head> <script> function notEmpty(elem, helperMsg){ if(elem.value.length == 0){ alert(helperMsg); elem.focus(); // set the focus to this input return false; } return true; } </script> </head> <body> <form action="mailto:fonzhende1@yahoo.com" method="post"> <table> <tr> <td>Name:</td> <td> <input type="text" name="name" value="" /> </td> </tr> <tr> <td>email address:</td> <td> <input type="text" name="email" value="" /> </td> </tr> <tr> <th></th> <td> <input type="submit" value="Submit" /> </td> </tr> </table> <textarea rows="2" cols="20"> Test area </textarea><br/> <br/> <select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select><br/> <br/> <input type="radio" name="group1" value="Milk"> Milk<br> <input type="radio" name="group1" value="Butter" checked> Butter<br> </form> </body> </html> Problem is when I submit the form I am getting what you see in the attachment, I guess this email form which pops up needs to be directed to Yahoo Hosting then redirected from there back to me? Anyway I would like if it the email could be sent directly to me without this form popping up, is that possible? Also, when I submit the form with the fields empty I am not getting the error message? |