JavaScript - Problem Validating Array
I have two arrays that are tied together Ink1Data[][InkID] and Ink1Data[][Ink1Desc]
I also have this Javascript code to validate it: Code: var chksink1 = document.getElementsByName("Ink1Data[][InkID]"); for (var i = 0; i < chksink1.length; i++) { switch (chksink1[i]) { case (chksink1.value=1); var i1Desc = "Ink1Data["+i+"][Ink1Desc]"; if (validate_required(i1Desc,"Please fill in a trim size.")==false) {i1Desc.focus();return false;} break; case (chksink1.value=2); var i1Desc = "Ink1Data["+i+"][Ink1Desc]"; if (validate_required(i1Desc,"Please fill in folding instructions.")==false) {i1Desc.focus();return false;} break; case (chksink1.value=3); var i1Desc = "Ink1Data["+i+"][Ink1Desc]"; if (validate_required(i1Desc,"Please fill in scoring instructions.")==false) {i1Desc.focus();return false;} break; } } basically, I want to count how many are in the array (will be the same number for both) and then depending on the value of the first array, validate the second and kick an appropriate error if necessary. it should be pretty easy, but I can't seem to get the code to work. Is there anyone that could please help me figure this out? Thank you! Similar TutorialsHi, I'm a student learning web design and having a problem with some javascript code, I'm validating a text area, i dont have a problem limiting how many characters can be typed in the textarea, but I cant get it to give an error if there is no text in the text area. In the code below the validateMes() function is not working, the other functions work fine Javascript code: Code: function validateLimit(fld){ var error =""; if(fld.value.length > 300){ error = "Cannot exceed 300 characters.\n" fld.style.background = 'Yellow'; }else{ fld.style.background = 'White'; } return error; } function validateMes(fld) { //this function not working var error = ""; if (fld.value.length == 0) { fld.style.background = 'Yellow'; error = "The Message field has not been filled in.\n" } else { fld.style.background = 'White'; } return error; } function validateFormOnSubmit(form1) { //master validating function var reason = ""; reason += validateLimit(form1.mess); reason += validateMes(form1.mess); if (reason != "") { alert("Some fields need correction:\n" + reason); return false; }else{ alert("Message has been submitted"); return true; } } Html form code: Code: <form name="form1" id="form1" onsubmit="return validateFormOnSubmit(this)" > <div class="box"> <h1>CONTACT FORM :</h1> <label> <span>Full name</span> <input type="text" class="input_text" name="name" id="name" value=""/> </label> <label> <span>Email</span> <input type="text" class="input_text" name="emailbox" id="emailbox" value=""/> </label> <label> <span>Subject</span> <input type="text" class="input_text" name="subject" id="subject" value=""/> </label> <label> <span>Message</span> <textarea class="message" name="mess" id="mess" ></textarea> <span>*Message limited to 300 characters</span> <input type="submit" class="button" value="Submit Form" /> </label> </div> </form> I can't see what I'm doing wrong, would really appreciate some help Thanks Code: <img class="border" alt="googtatic_map" src="http://maps.google.com/maps/api/staticmap?center=51.454863,0.011673&zoom=13&markers=United+Reformed+Church,+111+Burnt+Ash+Road,++Lee,+London+SE12+8RG,+UK&size=250x250&sensor=true" /> I have the above code and it is not validating with the w3c validation for XHTML it has thrown up 8 errors and 14 warnings. Should I ignore them or what? As I do like my code to validate. Hi im not good with javavscript so got some code off the net to do some rollovers, however it doesnt validate. can anyone please help me as to why this maybe? 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> <link rel="stylesheet" type="text/css" href="joho.css" /> <SCRIPT TYPE="text/javascript"> <!-- // copyright 1999 Idocs, Inc. http://www.idocs.com/tags/ // Distribute this script freely, but please keep this // notice with the code. var rollOverArr=new Array(); function setrollover(OverImgSrc,pageImageName) { if (! document.images)return; if (pageImageName == null) pageImageName = document.images[document.images.length-1].name; rollOverArr[pageImageName]=new Object; rollOverArr[pageImageName].overImg = new Image; rollOverArr[pageImageName].overImg.src=OverImgSrc; } function rollover(pageImageName) { if (! document.images)return; if (! rollOverArr[pageImageName])return; if (! rollOverArr[pageImageName].outImg) { rollOverArr[pageImageName].outImg = new Image; rollOverArr[pageImageName].outImg.src = document.images[pageImageName].src; } document.images[pageImageName].src=rollOverArr[pageImageName].overImg.src; } function rollout(pageImageName) { if (! document.images)return; if (! rollOverArr[pageImageName])return; document.images[pageImageName].src=rollOverArr[pageImageName].outImg.src; } //--> </head> <body> <div id="wrapper"> <div id="contentwrapper"> <div id="col1"> <ul> <li><A HREF="home.html" onMouseOver = "rollover('home')" onMouseOut = "rollout('home')" ><img src="menu/row1sq1_home_OP.png" border="0" alt="Home" NAME="home"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row1sq1_home_RO.png"); //--> </SCRIPT></li> <li><img src="menu/row2sq1_OP.png" alt="2"/></li> <li><A HREF="illustrations.html" onMouseOver = "rollover('illustrations')" onMouseOut = "rollout('illustrations')" ><img src="menu/row3sq1_illustrations_OP.png" border="0" alt="illustrations" NAME="illustrations"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row3sq1_illustrations_RO.png"); //--> </SCRIPT></li> <li><img src="menu/row4sq1_OP.png" alt="4"/></li> </ul> </div> <div id="col2"> <ul> <li><img src="menu/row1sq2_OP.png" alt="1"/></li> <li><img src="menu/row2sq2_OP.png" alt="2"/></li> <li><img src="menu/row3sq2_OP.png" alt="3"/></li> <li><A HREF="portraits.html" onMouseOver = "rollover('portraits')" onMouseOut = "rollout('portraits')" ><img src="menu/row4sq2_portraits_OP.png" border="0" alt="portraits" NAME="portraits"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row4sq2_portraits_RO.png"); //--> </SCRIPT></li> </ul> </div> <div id="col3"> <ul> <li><A HREF="about.html" onMouseOver = "rollover('about')" onMouseOut = "rollout('about')" ><img src="menu/row1sq3_about_OP.png" border="0" alt="About" NAME="about"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row1sq3_about_RO.png"); //--> </SCRIPT></li> <li><A HREF="cards.html" onMouseOver = "rollover('cards')" onMouseOut = "rollout('cards')" ><img src="menu/row2sq3_cards_OP.png" border="0" alt="cards" NAME="cards"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row2sq3_cards_RO.png"); //--> </SCRIPT></li> <li><img src="menu/row3sq3_squeak_OP.png" border="0" alt="1"/></li> <li><A HREF="contact.html" onMouseOver = "rollover('contact')" onMouseOut = "rollout('contact')" ><img src="menu/row4sq3_contact_OP.png" border="0" alt="contact" NAME="contact"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row4sq3_contact_RO.png"); //--> </SCRIPT></li> </ul> </div> <div id="col4"> <ul> <li><img src="menu/row1sq4_OP.png" alt="1"/></li> <li><img src="menu/row2sq4_OP.png" alt="2"/></li> <li><A HREF="weddings.html" onMouseOver = "rollover('weddings')" onMouseOut = "rollout('weddings')" ><img src="menu/row3sq4_wedding_OP.png" border="0" alt="weddings" NAME="weddings"/></a><SCRIPT TYPE="text/javascript"> <!-- setrollover("rollovers/row3sq4_wedding_RO.png"); //--> </SCRIPT></li> <li><img src="menu/row4sq4_OP.png" alt="4"/></li> </ul> </div> </div> </div> </body> </html> thank Q C Hi everyone, Would any of you know a cross-platform way to validate XML against XSD in JavaScript? All examples found online use MSXML, which is only available under Windows/IE. Using remote web-services is not a option, since the script should be able to run online. Cheers, Vit Hello all, I am pretty new to javascript and could use some help. I am validating a page (image attached) to make sure that total hours entered do not exceed the allocated amount, which is stored in the database. I have already validated to make sure that they enter a number and that it is not greater than 8. Could some one help me with the rest? thanks so much, Joe Code: var returncode = true var inputs = document.getElementsByTagName("INPUT") for(var x=0; x<inputs.length; x++) { if(inputs[x].type =='text' && isNaN(inputs[x].value)) { document.getElementById("hourserror").style.display = "block"; inputs[x].style.backgroundColor = '#FFCCCC'; returncode = false; } if(inputs[x].value > 8) { document.getElementById("totalerror").style.display = "block"; inputs[x].style.backgroundColor = '#FFCCCC'; returncode = false; } } return returncode; Hi guys! I have tried numerous attempts in getting the Address field to work (i.e. validated). I want it to accept letters, numbers, spaces and commas! However, it won't let me! Below is the code I have provided. Code: function validateAddress(fld) { var error = ""; var illegalChars = /[\W_]/; // } else if (illegalChars.test(fld.value)) { fld.style.background = 'Yellow'; error = "Your Billing address contains illegal characters!\n"; } else { fld.style.background = 'White'; } return error; } Thanks a lot! I managed to create the form that asks you to type in the information but I'm having some difficulty trying to figure out the alert to say "Thank you " after you have everything filled in and then hitting the button. my code is Code: <HTML> <HEAD> <TITLE> Form Validation Example </TITLE> <SCRIPT LANGUAGE="JavaScript"> function validatePersonalInfo(){ var _first = document.info.fname.value; var _city = document.info.city.value; var _phone = document.info.phone.value; if(_first.toString() == ""){alert("Please enter a first name.");} if(_city.toString() == ""){alert("Please enter your city.");} if(_phone.toString() == ""){alert("Please enter your phone number.");} var phoneInput = document.info.phone.value; var validPhone = false; var validCity = false; if(checkCity == true){ validCity = true; } else{ if(!checkPhone(phoneInput)){ alert("Phone number is invalid." + validPhone); } else{ validPhone = true; } if(validCity && validPhone){ alert("Your form has been verified"); } } } function checkPhone(str){ var regexp = /^(\d{10}|\d{3}-\d{3}-\d{4}|\(\d{3}\)\d{3}-\d{4})$/; return regexp.test(str); } function checkNum(length){ var cityLet = parseInt(cityEntry, 10); if (document.info.city.value.length == length){ if(cityLet != 0 && isNaN(cityLet) == false){ return true; } else { return false; } } else { return false; } } </script> </head> <body> <p> <form name="info" action="" method="post"> <table> <tr><td align="left">First Name:</td> <td align="left"> <input type="text" name="fname" size=15> </td> </tr> <br> </tr> <br> <tr> <td align="left">City:</td> <td align="left"> <input type="text" name="city" size=15> </td> </tr> <br> <tr><td align="left">phone</td> <td align="left"> <input type="text" name="phone" size=20></td> </tr> <br> </tr> <br> </table> <center> <input type="button" value="Submit" onClick="validatePersonalInfo()"> </center> </form> </body> </html> the help is greatly appreciated hi i need a help in java script. i have some text fields and when i enter the information in it and enter the validation button i need the results to be displayed in a box below these btns. Is it possible in Java script? Please see the attached image for some ideas. cheers Hi Folks I am trying to write a js that validates a form with two text inputs. The two inputs a 'D_techA' and 'D_techB'. I just want to add up (sum) the two input fields (which must be positive numbers) and make sure that they add up to exactly 100 (not more and not less). If they do not add up to 100, then an alert should pop up that says "The two values must add up to exactly 100." I have tried and tried to write a js that does this validation (looking at numerous validation scripts posted in this forum and elsewhere) and I just cannot seem to make it work. I would very much appreciate any suggestions! Thanks! The html code for my very simple form is: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <label>Investment in Tech A <input name="D_techA" type="text" id="D_techA" /> </label> <label>Investment in Tech B <input name="D_techB" type="text" id="D_techB" /> </label> <p> <input name="Submit" type="submit"/> </p> </form> </body> </html> Hi Guys, I use this code to validate e-mail addresses: PHP Code: // checks if the e-mail address is valid var emailPat = /^(".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/; var matchArray = formSignup.txtEmail.value.match(emailPat); if (matchArray == null) { alert("Your email address seems incorrect. Please try again (check the '@' and '.'s in the e-mail address)"); return false; } What i noticed today, is if a customer registers with an e-mail like: something.something@hotmail.com the first dot throws up the error, i'm not to great on regex lol any help would be appreciated thanks guys Graham I need to get an add on JS for this form to go with the current JS that is on it I need the add on JS to Validate all the fields have been filled out and then pop up an error if any of the fields are not filled out <FORM NAME="gather"><form onclick="return check(this);"> <fieldset> </p> <table width="200" border="0" cellpadding="10"> <tr> <th scope="row"><p align="left" class="style1">First Name*</p> <p> <div align="left"><input type="text" name="data_NameFirstName2" id="data_NameFirstName2" value="[Fname]"/> </p></th> </tr> <tr> <th scope="row"><p align="left" class="style1">Last Name*</p> <p> <div align="left"><input type="text" name="data_NameLastName2" id="data_NameLastName2" value="[Lname]"/> </p></th> </tr> <tr> <th scope="row"><p align="left" class="style1">Phone*</p> <p> <div align="left"><input type="text" name="phone1" id="phone1" /> </p></th> </tr> <tr> <th scope="row"><p align="left" class="style1">Email*</p> <p> <div align="left"><input type="text" name="email" id="email" /> </p></th> </tr> </table> </p> <p> <p><span class="style5">Please confirm your contact information.</span> <p><span class="style5"> (* = required) </span> <br /> <br /> <span class="style1"> <input type = "radio" name = "rad1" value = "Contact me"> <strong> Please contact me</strong></span></p> <p> <span class="style1">Please have my personal advisor</span></p> <p class="style1">contact me as soon as possible. <br /> <br /> </p> <p> <span class="style1"> <input type = "radio" name = "rad1" value = "Send me more info"> <strong>Send me more info</strong> </span></p> <p class="style1">I'm not ready to enroll yet, but</p> <p class="style1">please continue to send me more</p> <p class="style1">information and updates about </p> <p class="style1">going back to school <br /> <br /> </p> <p> <span class="style1"> <input type = "radio" name = "rad1" value = "Remove me from your mailing list"> <strong> No thanks </strong></span></p> <p class="style1"> Please remove me from your </p> <p class="style1">mailing list. <br /> <br /> </p> <label> <input type = "button" value = "submit" onclick ="chkrads()"> </label> </fieldset> </form> <script type = "text/javascript"> function chkrads() { var chosen = "None"; var which = -1; var len = document.gather.rad1.length; for (i = 0; i < len; i++) { if (document.gather.rad1[i].checked) { chosen = document.gather.rad1[i].value; which = i; } } if (chosen == "None") { alert("No Location Chosen"); } else { } if (which == 0) {window.location = "http://www.hudsonsd.com/national2010/thankcontact.html"} if (which == 1) {window.location = "http://www.hudsonsd.com/national2010/thanksend.html"} if (which == 2) {window.location = "http://www.hudsonsd.com/national2010/thanknocontact.html"} } </script> Thanks! okay, my main question here is, can you nest a function in an if statement? it seems to me that you cant.. gosh validating dates is difficult. Code: var userBDay = document.getElementById('BDay').value; var retVal = true; var errorMsg = ""; if (userBDay == "") { assignErrorClass("BDay"); errorMsg = errorMsg + "Please Enter a Birthday.\n"; retVal = false; } if (userBDay !== "") { if (badBirthday(userBDay)) { assignErrorClass("BDay"); errorMsg = errorMsg + "Invalid Birthday\n"; retVal = false; } else { retVal = true } } if (!retVal) { alert( errorMsg); } return retVal; function badBirthday (objName) { var obj = document.getElementById(objName); var dateStr = obj.value; var m = dateStr.split("/")[0]; var d = dateStr.split("/")[1]; var y = dateStr.split("/")[2]; var dateObj = new Date(y,m-1,d); //JavaScript and PHP number the months 0 to 11. if (dateObj.getFullYear() != y || dateObj.getMonth()+1 != m || dateObj.getDate() != d) { return true; //if invalid bithday } else { return false; //if valid bithday } } much thanks! Hello, So all I need to do is have a checkbox above the 'submit' button that the user must check before the button becomes active. Once the user checks the checkbox, then the button becomes active - and users can click on this button to get to the new page. However, I haven't found any tutorials online that handle this exactly. What I have found is example scripts that have multiple checkboxes, etc...and if I try to remove any of them from the script, it seems to mess up the functionality. So - take this for example. This would actually work perfect, if the male/female option wasn't there, and the 'reset' wasn't there either: Quote: <head> <script type="text/javascript"> function validate(form) { // Checking if at least one period button is selected. Or not. if (!document.form1.sex[0].checked && !document.form1.sex[1].checked){ alert("Please Select Sex"); return false;} if(!document.form1.agree.checked){alert("Please check the terms and conditions"); return false; } return true; } </script> </head> <body> <table border='0' width='50%' cellspacing='0' cellpadding='0' ><form name=form1 method=post action=action_page.php onsubmit='return validate(this)'><input type=hidden name=todo value=post> <tr bgcolor='#ffffff'><td align=center ><font face='verdana' size='2'><b>Sex</b><input type=radio name=sex value='male'>Male </font><input type=radio name=sex value='female'><font face='verdana' size='2'>Female</font></td></tr> <tr><td align=center bgcolor='#f1f1f1'><font face='verdana' size='2'><input type=checkbox name=agree value='yes'>I agree to terms and conditions </td></tr> <tr bgcolor='#ffffff'><td align=center ><input type=submit value=Submit> <input type=reset value=Reset></td></tr> </table> </body> I try to manually remove the 'male/female' options for this in Dreamweaver, but then the script doesn't work properly. Can anybody help me out here? Would be greatly appreciated. Thank you <HTML> <HEAD> <TITLE>Form Validation Example </TITLE> <SCRIPT LANGUAGE="JavaScript"> <!-- function validateForm() { if(document.UD.FIRST_NAME.value=="") { alert("PLEASE FILL IN THE First Name FIELD"); return(false); }// validation for empty first name if(document.UD.LAST_NAME.value=="") { alert("PLEASE FILL IN THE Last Name FIELD"); return(false); }// validation for empty last name if(document.UD.MONTH.value=="") { alert("PLEASE FILL IN THE Birth Date FIELD"); return(false); }//validation for empty month if(document.UD.DAY.value=="") { alert("PLEASE FILL IN THE Birth Date FIELD"); return(false); } //validation for empty day if(document.UD.YEAR.value=="") { alert("PLEASE FILL IN THE Birth Date FIELD"); return(false); }//validation for empty year if(document.UD.MONTH.value >=1 && document.UD.MONTH.value <=12) { return(true); } else{ alert("Please enter a valid Month"); return(false); } /* this runs its course but stops after it makes this statement true. It does not continue the last to if statements. I have rearranged the code to read: if(document.UD.MONTH.value <=0) { alert("Please enter a valid Month"); return(false); } if(document.UD.MONTH.value >=12) { alert("Please anter a valid Month") return(false); } but by following these statments it skips these and goes straight to the next if statement and follows that until it reaches true then it won't go onto the last if statment.*/ if(document.UD.DAY.value >=1 && document.UD.DAY.value <=32) { return(true); } else{ alert("Please enter a valid day"); return(false); } if(document.UD.YEAR.value >=1900 && document.UD.YEAR.value <=2011) { return (true); } else { alert("Please enter a valid year"); return(false); } return(true); } //--> </SCRIPT> </HEAD> <BODY> <CENTER> <FONT SIZE="5" COLOR="#006600" FACE="verdana">Form Validation</FONT> </CENTER><BR><BR> <FORM METHOD=POST ACTION="http://www.mysite.com" NAME="UD"> <TABLE ALIGN="CENTER"> <TR> <TD>First Name</TD> <TD><INPUT TYPE="TEXT" NAME="FIRST_NAME"></TD> </TR> <TR> <TD>Last Name</TD> <TD><INPUT TYPE="TEXT" NAME="LAST_NAME"></TD> </TR> <TR> <TD>Birth Date</TD> <TD><INPUT TYPE="TEXT" SIZE="4" NAME="MONTH"><INPUT TYPE="TEXT" SIZE="4" NAME="DAY"><INPUT TYPE="TEXT" SIZE="6" NAME="YEAR"> </TD> </TR> <TR> <TD><INPUT TYPE="SUBMIT" VALUE="Submit Form" onClick="return validateForm()"></TD> <TD><INPUT TYPE="RESET" VALUE="Reset"></TD> </TR> </TABLE> </FORM> </BODY> </HTML> Above is my code. I have included a brief snippet of my problem in the code already, but basically my code runs through all the if statements until it gets to the if statement about the month and validating what numbers are used. Once it completes that if statement it returns true and goes no further. However if I rearrange my code it still does not work. If anyone has some idea on what I am doing I would greatly appreciate it. I am new to javascript and have been working on this for hours upon hours trying to figure it out so any help would be greatly appreciated. Thank you. We are trying to validate a piece of code on our HTML pages and get the following message - "The text content of element script was not in the required format: Expected space, tab, newline, or slash but found < instead." The code is used to set up the Facebook tags in JavaScript, and does work by itself. However, we're trying to get it to work through validation on http://validator.w3.org Code: <script src="SiteTools.js"> //<![CDATA[ <!-- FacebookSetup('CABLED Project first 6 months', 'images/angela-imiev.jpg'); //--> //]]> </script> Thanks Just wondering what the code would be to validate the radio buttons, thus when i click get score a pop up will tell me that one of the radio buttons was not selected. If you really want to help me it would be good if i was able to have get score and submit working on one button, and validating every field. My code is below (don't mind the questions and answers ) Code: <HEAD> <script language="JavaScript"> var numQues = 5; var numChoi = 3; var answers = new Array(5); answers[0] = "Life"; answers[1] = "Disturbing"; answers[2] = "Yahoo Answers"; answers[3] = "Playing Video Games in the Basement"; answers[4] = "About the portion of my Sandwich"; function getScore(form) { var score = 0; var currElt; var currSelection; for (i=0; i<numQues; i++) { currElt = i*numChoi; for (j=0; j<numChoi; j++) { currSelection = form.elements[currElt + j]; if (currSelection.checked) { if (currSelection.value == answers[i]) { score++; break; } } } } score = Math.round(score/numQues*100); form.percentage.value = score + "%"; var correctAnswers = ""; for (i=1; i<=numQues; i++) { correctAnswers += i + ". " + answers[i-1] + "\r\n"; } form.solutions.value = correctAnswers; } function validate_required(field,alerttxt) { with (field) { if (value==null||value=="") { alert(alerttxt);return false; } else { return true; } } } 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("Please Enter a Valid E-mail") return false } if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(at,(lat+1))!=-1){ alert("Please Enter a Valid E-mail") return false } if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(dot,(lat+2))==-1){ alert("Please Enter a Valid E-mail") return false } if (str.indexOf(" ")!=-1){ alert("Please Enter a Valid E-mail") return false } return true } function validate_form(thisform) { with (thisform) { if (validate_required(Name,"Name must be filled out!")==false) {Name.focus();return false;} if (validate_required(Surname,"Surname must be filled out!")==false) {Surname.focus();return false;} { var emailID=document.submitting.email if ((emailID.value==null)||(emailID.value=="")){ alert("Please Enter a Valid E-mail") emailID.focus() return false } if (echeck(emailID.value)==false){ emailID.value="" emailID.focus() return false } return true } } } </script> </HEAD> <BODY> <h3>Quiz</h3> <form name="quiz"> 1. What do i win at..? <ul style="margin-top: 1pt"> <li><input type="radio" name="q1" value="Life">Life</li> <li><input type="radio" name="q1" value="Nothing At All">Nothing At All</li> <li><input type="radio" name="q1" value="Using a Computer">Using a Computer</li> </ul> 2. My Life is..? <ul style="margin-top: 1pt"> <li><input type="radio" name="q2" value="Boring">Boring</li> <li><input type="radio" name="q2" value="Disturbing">Disturbing</li> <li><input type="radio" name="q2" value="Like everyone elses">Like everyone elses</li> </ul> 3. I don't learn off my mother i learn off ..? <ul style="margin-top: 1pt"> <li><input type="radio" name="q3" value="Google">Google</li> <li><input type="radio" name="q3" value="Yahoo Answers">Yahoo Answers</li> <li><input type="radio" name="q3" value="The Bible">The Bible</li> </ul> 4. I Spend Most of my time ..? <ul style="margin-top: 1pt"> <li><input type="radio" name="q4" value="Cutting Down Palm Tree's">Cutting Down Palm Tree's</li> <li><input type="radio" name="q4" value="Eating">Eating</li> <li><input type="radio" name="q4" value="Playing Video Games in the Basement">Playing Video Games in the Basement</li> </ul> 5. I Complain the most about ..? <ul style="margin-top: 1pt"> <li><input type="radio" name="q5" value="JavaScript">JavaScript</li> <li><input type="radio" name="q5" value="About the portion of my Sandwich">About the portion of my Sandwich</li> <li><input type="radio" name="q5" value="Lag">Lag</li> </ul> <input type="button" value="Get score" onClick="getScore(this.form)"> <input type="reset" value="Clear answers"> <p> Score = <strong><input class="bgclr" type="text" size="5" name="percentage" disabled></strong><br><br> Correct answers:<br> <textarea class="bgclr" name="solutions" wrap="virtual" rows="4" cols="30" disabled> </textarea> </form> <form action="submit.htm" onsubmit="return validate_form(this)" method="post" name="submitting"> Name: <input type="text" name="Name" size="30"> <br> <br> Surname: <input type="text" name="Surname" size="30"><br><br> Email: <input type="text" name="email" size="30"><br> <form action="submit.htm" onSubmit="return validate_form(this)" method="post"> <input type="submit" value="Submit" > </form> </body> Here's what I have so far in my validation part. However, I need help as to how to validate the following fields when the user clicks the submit button. -Radio Button *title (4 options) *member (3 options) *vegetarian (2 options) -Drop down lists *regstartdate (3 options) *regenddate (3 options) *confdinner (2 options) *paymethod (3 options) -UK Post Code (text box with maxlength=8) My current code shows 1 popup with all the error messages. Here's what I have so far: Redacted Hi! I am trying to check and see if three fields are empty and if they are then to alert the user saying to fill in one of the three fields. I tried this: Code: if (StreetNumber.value.length == 0) { if (StreetName.value.length == 0) { if (City.value.length == 0) { alert("Please enter a street number, street name, or city."); StreetNumber.focus(); return false; } } } and this: Code: if (StreetNumber.value.length == 0 && StreetName.value.length == 0 && City.value.length == 0) { alert("Please enter a street number, street name, or city."); StreetNumber.focus(); return false; } Neither one works. Not sure what I am doing wrong. Thanks in advance! |