JavaScript - Checksum Validation Problem!
Hello,
I 'm working on Euro banknote validation, where I'm using authentication of the serial number of Euro banknotes by the calculation of the "checksum". Basically what this algorithm does is to replace the first letter of the serial number by a number (each letter represents where the banknote is originally from), then it calculates the sum of all digits. If the remaining of the division of that sum by 9 is 0 then your note is valid. More info:http://en.wikipedia.org/wiki/Euro_banknotes#Checksum. Some test data. EURO Serial Number V44671133335 T27620110932 A00000000007 The last serial number "A00000000007" works properly. but the first two for some reason don't work properly. Those are my javascript codes: Code: <html> <body> <script type="text/javascript"> var EBNSArray = new Array ("0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "0", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"); function validation() { var i; var EBNS = document.forms["ebnsform"]["EBNS"].value; if (EBNS.length != 11 && EBNS.length != 12) { alert ("Incorrect EBNS, please enter the correct EBNS"); return false; } if (EBNS.length == 11) { var letter_real = EBNS.charAt(0); } if (EBNS.length == 12) { var letter_real = EBNS.charAt(1); } var letter_enter = EBNS.substring(1,11); var checkLetter = letter_enter % 9 if (letter_real == EBNSArray[checkLetter]) { alert ("Correct EBNS"); return true; } else { alert ("Incorrect EBNS, please enter the correct EBNS"); return false; } } </script> <form id="ebnsform"> <P>Euro Banknote Number: <input type="text" id="EBNS" /><br /></form></center> <input type="button" onclick="validation()" value="Validation"/></p> </body> </html> Similar TutorialsHi 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, 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; } } 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? 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! 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 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! 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 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; } } Having an unusual problem with the simple validation script below. In my script, I want to validate the username text field so that if the value of the text field (i.e. the amount of characters in the field) is less than 5, it would show a message in the page using innerHTML. The script works, but in a roundabout sort of way, or at least that's what it seems to me. Instead of making sure that the amount of characters in the text field is less than 5, it seems to disregard this entirely and instead make it so that if it has no value at all, the message will be shown. If it has a value of even 1 character, though, the message does not show. Not what I was trying to do, and I really don't know what's happened. Thanks in advance to anyone who can help out a newbie in need. Code: function uservalidate() { if (document.getElementById("user").value < 5) { document.getElementById("userdiv").innerHTML = "Username must be six characters or more." } else { document.getElementById("userdiv").innerHTML = "" } } Code: <body> <form id="form1"> <input type="text" id="user" onblur="uservalidate()" /> <div id="userdiv"></div> </form> </body> </html> Hello guys, I have implemented the jquery validation in one of my projects. I have a <div> which has all the billing details & another <div> below it which has the shipping details. There is a checkbox in between these <div>'s which says "Same as Billing Address". It is used to populate all the shipping fields from the billing fields. Well, on this particular form there are some fields which are mandatory & which I have validated by jquery validation. I have used the $("#form_id").validate().form(); statement to check validation on the click event of the checkbox. The actual problem is that after page loads, I directly click on the checkbox & submit the page, the page gets submitted & validation does not execute. If I click the submit button with the checkbox unchecked then the validation runs properly. Why is my form not being validated if I checked the checkbox? Please guys, help me out. Thanks in advance. Bhavik. I am currently trying to fix a problem on the form submission on my site. On the Request Information page I am using MM_validateForm function and the FormtoEmail.php script. When required fields are blank, you are alerted via pop-up notification when hitting submit. Afterwards though, the form still sends without letting you finish completing required fields. I have noticed that if the First Name field is blank the form will not send, but any other field it just still sends. I have looked this up on Google endlessly and have tried every 'fix'. This is the function: Code: <script type="text/javascript"> <!-- function MM_validateForm() { //v4.0 if (document.getElementById){ var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments; for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=document.getElementById(args[i]); if (val) { nm=val.name; if ((val=val.value)!="") { if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@'); if (p<1 || p==(val.length-1)) errors+='- '+nm+' Must Contain an Email Address.\n'; } else if (test!='R') { num = parseFloat(val); if (isNaN(val)) errors+='- '+nm+' Must Contain a Valid Phone Number.\n'; if (test.indexOf('inRange') != -1) { p=test.indexOf(':'); min=test.substring(8,p); max=test.substring(p+1); if (num<min || max<num) errors+='- '+nm+' Must Contain a Number Between '+min+' and '+max+'.\n'; } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' Is Required.\n'; } } if (errors){ alert('Please Complete All Required Fields:\n'+errors); } document.MM_returnValue = (errors ==''); } } //--> This is the form html code: Code: <form action="FormToEmail.php" method="post" name="myform" class="cmxform" id="myform" onsubmit="MM_validateForm('first-name','','R');MM_validateForm('last-name','','R');MM_validateForm('workphone','','RisNum');MM_validateForm('address1','','R');MM_validateForm('city','','R');MM_validateForm('state','','R');MM_validateForm('country','','R');return document.MM_returnValue;"> This is the code on the submit button: Code: <input type="submit" class="buttons" onClick="MM_validateForm('first-name','','R');MM_validateForm('last-name','','R');MM_validateForm('workphone','','RisNum');MM_validateForm('address1','','R');MM_validateForm('city','','R');MM_validateForm('state','','R');MM_validateForm('country','','R');return document.MM_returnValue;" value="Send"/> I may be missing something really obvious but i've gone over this for three days. I just recently have moved positions to Website Designer and my main background is in Graphic Design so my knowledge is very minimal. I created this site in a month due to time restrictions and the code is far from perfect. any help would be greatly appreciated. thanks! EDIT: sorry sorry, I just realized I posted this on the wrong place.... {palmface} Just to start off, Javascript is NOT my forte'. Ive been trying to do some form validating for a few hours now. I've tried many different combos and trying multiple functions to make this work but I have seemed to make more of a mess than anything now. Here's what I've got going on... A simple form with 3 text inputs a checkbox and a submit button. I'm trying to do 7 things. 1. strip special characters from all 3 input fields (except : / and @) 2. make sure no input fields are blank 3. verify that email has @ and . in it 4. insure that the checkbox is checked I would love to set the email not to allow certain domains(yahoo,gmail) but that is a bit out of my league. Any help would be appreciated, below is the current garbled mess of javascript I am left with after hours of trying to get it to work... my appologies. I know it's ugly. Code: <script LANGUAGE="Javascript"> <!-- Begin function CleanUp() { name = document.register.name.value; email = document.register.email.value; website = document.register.website.value; var iChars = "!#$%^&*()+=-[]\';,.{}|\"<>?"; //remove crap name for (var i = 0; i < document.register.name.value.length; i++) { if ((iChars.indexOf(document.register.name.charAt(i)) != -1)) { window.alert ("No special characters allowed."); return false; }} //remove crap website for (var i = 0; i < document.register.website.value.length; i++) { if ((iChars.indexOf(document.register.website.charAt(i)) != -1)) { window.alert ("No special characters allowed."); return false; }} //remove crap email for (var i = 0; i < document.register.email.value.length; i++) { if ((iChars.indexOf(document.register.email.charAt(i)) != -1)) { window.alert ("No special characters allowed."); return false; }} //check required field if ((name == "") || (email == "")|| (website == "")) { window.alert("Please enter your Name, website, and E-mail address."); return false; } //verify email if (email.value.indexOf("@", 0) < 0) { window.alert("Please enter a valid e-mail address."); return false; } if (email.value.indexOf(".", 0) < 0) { window.alert("Please enter a valid e-mail address."); return false; } // check agree term before submit if (agree.checked == false ) { alert('Please confirm you are the site owner.'); return false; //done }else return true; } // End --> </script> Hi All, I am trying to create a script for checking that checks that the email address entered into two input boxes is the same when a submit button is clicked, I have these two input boxes Code: <input type="text" name="user_email" id="user_email" /> <input type="text" name="user_email2" id="user_email2" /> This javascript code Code: <script type="text/javascript"> var email1 = document.getElementById(user_email); var email2 = document.getElementById(user_email2); function checkEmail(){ if (email1 != email2) { alert("The two email addresses are not the same"); } } </script> and this code for the button Code: <input type="submit" name="submit" id="submit" onSubmit="checkEmail" /> However this code is not working, can anyone see where I am going wrong? Any help will be appreciated Thanks in advance can anyone help me validate a survey page i have? it has many questions and each question has 5 radio buttons. i followed many guides and none of them worked for me. I refered to http://www.dynamicdrive.com/forums/s...00&postcount=9 guide and http://javascript.about.com/library/blradio4.htm but for somereason it doesn't seem to work. So can u guys plz look over my simplified version of the survey and see whats is wrong. Sorry if i sound like a noob, I am new here. 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" /> <title>Untitled Document</title> <script type="text/javascript"> var btn = valButton(form.q1); if (btn == null) alert('No radio button selected'); else alert('Button value ' + btn + ' selected'); function valButton(btn) { var cnt = -1; for (var i=btn.length-1; i > -1; i--) { if (btn[i].checked) {cnt = i; i = -1;} } if (cnt > -1) return btn[cnt].value; else return null; } </script> </head> <body> <table width="800" border="1" cellspacing="0" cellpadding="20"> <form name="science" method="post" action="ad.html" onsubmit="return valButton(btn);"> <tr> <td width="475"><h3> <center> Reasons for organizing Science Olympiad </center> </h3></td> <td width="17"><h3> <center> 1 </center> </h3></td> <td width="17"><h3> <center> 2 </center> </h3></td> <td width="17"><h3> <center> 3 </center> </h3></td> <td width="17"><h3> <center> 4 </center> </h3></td> <td width="17"><h3> <center> 5 </center> </h3></td> </tr> <tr> <td width="475">1. It is fun</td> <td width="17"><input type="radio" id="q1" name="q1" value="1" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="2" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="3" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="4" /></td> <td width="17"><input type="radio" id="q1" name="q1" value="5" /></td> </tr> <tr> <td>2. To motivate students to pursue further education in Science and Engineering</td> <td width="17"><input type="radio" id="q2" name="q2" value="1" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="2" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="3" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="4" /></td> <td width="17"><input type="radio" id="q2" name="q2" value="5" /></td> </tr> <tr> <td><input type="submit" name="submit" /></td> </tr> <tr></tr> </form> </table> testing </body> </html> I have two seperate js files. One that houses the functions mylibrary.js and another that call the validated functions myform.js. I can not get the form to validate any data. The data just sits there and will not report errors. Any help would be greatly appreciated. Code: function valForm() { if(!isAlpha(document.myform.firstname.value)) { myform.firstname.focus(); return false; } if(!validEmail(document.myform.email.value)) { myform.email.focus(); return false; } if(!isRequired1(document.myform.options.value)) { myform.options.focus(); return false; } return true; } // JavaScript Document seperate js file mylibrary.js function isNumber(num) { return !(/\D/.test(num)); } function isAlpha(text){ return text.match(/\w+/) } function validEmail(email){ return email.match(/^([a-zA-Z0-9]{3,})(((\.|\-|\_)[a-zA-Z0-9]{2,})+)?@([a-z]{3,})(\-[a-z0-9]{3,})?(\.[a-z]{2,})+$/i ) } function isRequired1(){ if(myform.food.selectedIndex ==0) { alert("Please select from the drop-down list."); } } Hi Everybody. i have a contact form here PHP Code: <form id="form1" method="post" action="/contact.php" onsubmit="return validate(this)"> <p> <label for="name">Name:</label> <input type="text" name="name" id="name" /> <img src="alert.gif" alt="" class="alertImg" /> </p> <p> <label for="number">Mobile:</label> <input type="text" name="number" id="number" /> <img src="alert.gif" alt="" class="alertImg" /> </p> <p> <label for="email">Email:</label> <input type="text" name="email" id="email" /> <img src="alert.gif" alt="" class="alertImg" /> </p> <p> <label for="msg">Comments:</label> <textarea name="msg" id="msg" cols="30" rows="3"></textarea> <img src="alert.gif" alt=""class="alertImg" /> </p> <p> <input class="submit_btn" type="image" src="images/submit_btn.gif" name="submit" value="Submit" /></p> <!-- --> </form> and i have an external js script to validate the form and the code is below PHP Code: var alertImgs = []; var nImage = ""; function validate(nForm){ for (i=0; i<alertImgs.length; i++) { nImage[alertImgs[i]].style.visibility = "hidden"; } var nName = nForm['name']; var nMobile = nForm['number']; var nEmail = nForm['email']; if (nFirstName.value.replace(/s/g, "").length < 1) { alert('Please Enter Your Name'); document.images[alertImgs[0]].style.visibility = "visible"; return false; } if (!/[ds-]+$/.test(nmobile.value) || !/d{10}/.test(nmobile.value.replace(/[s-]/g, ""))) // must contain 10 digits; { alert('Enter your mobile phone number'); document.images[alertImgs[2]].style.visibility = "visible"; return false; } if (!/^w+[w|.|-]{0,1}w*[w|.|-]{0,1}w*@w+[w|-]{0,1}w*[w|-]{0,1}w*.{1,1}[a-z]{2,4}$/.test(nEmail.value)) { alert('Invalid Email'); document.images[alertImgs[3]].style.visibility = "visible"; return false; } if (nForm['msg'].value == "") { alert('Please write a comment'); document.images[alertImgs[4]].style.visibility = "visible"; return false; } alert('Thank you for your submission'); return true; } function init(){ nImage = document.images; var imgFileName = ""; for (i=0; i<nImage.length; i++) { imgFileName = nImage[i].src; imgFileName = imgFileName.substring(imgFileName.lastIndexOf("/")+1,imgFileName.length) if (imgFileName == "alert.gif") { alertImgs[alertImgs.length] = i; nImage[i].style.visibility = "hidden"; } } } navigator.appName == "Microsoft Internet Explorer" ? attachEvent('onload', init, false) : addEventListener('load', init, false); Could anyone tell me why it wont work for me and is there any problem with the code? Thanks for your help if you give some I made a post a really long time ago and can't find my original post so I am re-posting. The code has changed a little and not sure where to go from here. I am trying to validate US and Canada zipcodes based on the Country selection. So if I select Country US validate zip for US or if I select Country Canada validate zip for Canada. I really don't know javascript and this code was sent to me but it doesn't work and can't make sense of what to do. Can anyone please help? I am attaching the code. Code: <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%> <!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" /> <title>Untitled Document</title> <script> function checkForOther(obj) { test = obj.value if (!document.layers) { var txt = document.getElementById("otherTitle"); if (obj.value == "US") txt.style.display = "inline"; else (obj.value == "CA") txt.style.display = "inline"; { } } } </script> <script type = "text/javascript"> function validZip(zip) { var reUS = /^([0-9]{5})(?:[-\s]*([0-9]{4}))?$/, // US Zip reCA = /^([A-Z][0-9][A-Z])\s*([0-9][A-Z][0-9])$/; // CA Zip return zip.match(reUS) || zip.match(reCA); } </script> </head> <body> <form action="https://www.amm.org/memserv/survey/surveypg2.asp" method="post" name="survey1" id="survey1" onKeyUp="highlight(event)" onClick="highlight(event)"> <p><strong>Country: </strong> <select name="selTitle" id="titles" onchange="checkForOther(this)"> <option value="0">**</option> <option value="CA">Canada</option> <option value="US">United States</option> </select> </p> <p><strong>US Zip Code: </strong> <input name="ZIP" type="text" id="otherTitle" style="display:none;" onchange="if (validZip(this.value)) {alert('*** Please enter a valid zip code.');}"/> <!--<input type="text" id="otherTitle" name="zip" style="display:none;" maxlength="10" onchange ="validZip(this.value)">--> </p> </form> </body> </html> Hi I have a problem with a form in my site he http://www.21centuryanswers.com/submit.php if no field is filled and you click submit, an alert will be shown, yet the next page will still load! How do I fix it? the code for the form is: <form action="privacy.php" method="post" onsubmit="return checkform(this);"> <fieldset> <center> E-mail: <input type="textfield" name="email" size="60" value="" /><br/></br> Question: <input type="textfield" name="question" size="70" value="" /><br/><br/> <input type="submit" value = "Submit"/> </center> </fieldset> </form> and here is the validation script: <script language="JavaScript" type="text/javascript"> <!-- function checkform ( form ) { // ** START ** if (form.email.value == "") { alert( "Please enter your email." ); form.author.focus(); return false ; } if (form.question.value == "") { alert( "Please enter the question." ); form.title.focus(); return false ; } // ** END ** return true ; } //--> </script> Please help! |