JavaScript - How To Validate This Js Code For Xhtml Strict
This the html code below. Im getting a few errors
1) there is no attribute "onload" and 2) there is no attribute "name" PHP Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Navigation</title> <link href="css/new.css" rel="stylesheet" type="text/css"/> <script type="text/javascript" src="js/nav.js"></script> </head> <body onload="MM_preloadImages('images/tab1.gif','images/tab1hover.gif','images/tab2hover.gif','images/tab3hover.gif','images/tab4hover.gif','images/tab5hover.gif')"> <div id="wrapper"> <div id="top"> <div id="topright"> <div id="primaryNavWrapper"> <div id="primaryNav"> <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab1','images/tab1hover.gif',1)" onmouseover="MM_nbGroup('over','tab1','images/tab1hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab1hover.gif" alt="Home" name="tab1" width="79" height="31" id="home" onload="MM_nbGroup('init','group1','tab1','images/tab1.gif',1)" /></a> <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab2','images/tab2hover.gif',1)" onmouseover="MM_nbGroup('over','tab2','images/tab2hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab2.gif" alt="About Us" name="tab2" width="95" height="31" id="aboutUs" /></a> <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab3','images/tab3hover.gif',1)" onmouseover="MM_nbGroup('over','tab3','images/tab3hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab3.gif" alt="Services" name="tab3" width="89" height="31" id="services" /></a> <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab4','images/tab4hover.gif',1)" onmouseover="MM_nbGroup('over','tab4','images/tab4hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab4.gif" alt="Testimonials" name="tab4" width="120" height="31" id="testimonials" /></a> <a href="javascript:;" onclick="MM_nbGroup('down','group1','tab5','images/tab5hover.gif',1)" onmouseover="MM_nbGroup('over','tab5','images/tab5hover.gif','',1)" onmouseout="MM_nbGroup('out')"><img src="images/tab5.gif" alt="Contact Us" name="tab5" width="108" height="31" id="contactUs" /></a> </div> </div> </div> </div> </div> </body> </html> and here is the js code PHP Code: function MM_preloadImages() { //v3.0 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array(); var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++) if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}} } function MM_findObj(n, d) { //v4.01 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) { d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);} if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n]; for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); if(!x && d.getElementById) x=d.getElementById(n); return x; } function MM_nbGroup(event, grpName) { //v6.0 var i,img,nbArr,args=MM_nbGroup.arguments; if (event == "init" && args.length > 2) { if ((img = MM_findObj(args[2])) != null && !img.MM_init) { img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src; if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array(); nbArr[nbArr.length] = img; for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) { if (!img.MM_up) img.MM_up = img.src; img.src = img.MM_dn = args[i+1]; nbArr[nbArr.length] = img; } } } else if (event == "over") { document.MM_nbOver = nbArr = new Array(); for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) { if (!img.MM_up) img.MM_up = img.src; img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up); nbArr[nbArr.length] = img; } } else if (event == "out" ) { for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; } } else if (event == "down") { nbArr = document[grpName]; if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; } document[grpName] = nbArr = new Array(); for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) { if (!img.MM_up) img.MM_up = img.src; img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up; nbArr[nbArr.length] = img; } } } Any help would be greatly appreciated Similar TutorialsAll, So I have the following code. It works great. When I add this: Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> It doesn't work. I need it for some aspects of my CSS to work. The code that works without that is: Code: <html> <script> function resizeAll( ) { var divs = document.getElementsByTagName("div"); for ( var d = 0; d < divs.length; ++d ) { var div = divs[d]; if ( div.className == "fn-area" ) { divid = divs[d].getAttribute("id"); imgid = "Img" + divid; var Div1Width, Div1Height; Div1Width = document.getElementById(divid).offsetWidth; Div1Height = document.getElementById(divid).offsetHeight; document.getElementById(imgid).style.width = Div1Width; document.getElementById(imgid).style.height = Div1Height; } } } </script> <head> </head> <body onLoad="resizeAll()"> <div id="Div1" class="fn-area" style="width:100px;height:100px; border:1px solid black;" onmouseover="document.getElementById('ImgDiv1').style.display='block';" onmouseout="document.getElementById('ImgDiv1').style.display='none';"> <img id="ImgDiv1" src="fnclientlib/styles/artwork/creep_stamp5.gif" style="display:none"/> </div> <div id="Div2" class="fn-area" style="width:300px;height:300px; border:1px solid black;" onmouseover="document.getElementById('ImgDiv2').style.display='block';" onmouseout="document.getElementById('ImgDiv2').style.display='none';"> <img id="ImgDiv2" src="fnclientlib/styles/artwork/creep_stamp5.gif" style="display:none"/> </div> </body </html> Hi, I want to validate the value in a textbox such that the first character should be a symbol like # or $ followed by 2 alphabets which is followed by numbers.I tried a pattern like if(/(#{1}|${1})\D{2}\d{6}/.test(str.value)) But this is not working. Can someone help me the correct pattern? Hello all, I have a form that submits a POST request when data is submitted. A Servlet then processes this POST request and a JavaBean is used to make some calculations. The HTML response is not generated within the Servlet but instead I forward the request to a JSP to generate the response. - This all works fine, thankfully. However, I am stupidly suck trying to validate the form on the client side with a JavaScript function before the form is submitted. Here is my index.jps: Code: <%-- Document : index Created on : 19-Nov-2009, 13:41:30 Author : lk00043 --%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/JavaScript"> <!-- Start hiding JavaScript Statements function validateForm() { var student; var score1, score2, score3, score4; student = document.getElementById('student'); s1 = document.getElementById('score1'); s2 = document.getElementById('score2'); s3 = document.getElementById('score3'); s4 = document.getElementById('score4'); score1 = parseInt(s1.value); score2 = parseInt(s2.value); score3 = parseInt(s3.value); score4 = parseInt(s4.value); if(student.value.length == 0) { document.getElementById('StudentError1').innerHTML = " Enter a student name!"; return false; } if ((isNaN(score1)) || (score1 < 0) || (score1 > 100)) { document.getElementById('Error1').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score2)) || (score2 < 0) || (score2 > 100)) { document.getElementById('Error2').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score3)) || (score3 < 0) || (score3 > 100)) { document.getElementById('Error3').innerHTML = " Enter a number between 0 and 100!"; return false; } if ((isNaN(score4)) || (score4 < 0) || (score4 > 100)) { document.getElementById('Error4').innerHTML = " Enter a number between 0 and 100!"; return false; } } // End hiding JavaScript Statements --> </script> <title>Lab Class 7 - Task 2</title> </head> <body> <h1>Lab Class 7</h1> <form name="collectgrades" action="AssessGrades" method="POST" onSubmit="validateForm()" > Name of Student: <input type="text" name="student" id="student"/><span id="StudentError1"> </span><br /> Presentation: <input type="text" name="score" id="score1"/><span id="Error1"> </span><br /> Writing style: <input type="text" name="score" id="score2"/><span id="Error2"> </span><br /> Technical content: <input type="text" name="score" id="score3"/><span id="Error3"> </span><br /> Depth of analysis: <input type="text" name="score" id="score4"/><span id="Error4"> </span><br /> Feedback:<select name="feedback" size="4" multiple="multiple"> <option>"Could be better structured."</option> <option>"Depth of analysis is good."</option> <option>"Very advanced material."</option> <option>"Very well structured."</option> </select><br /> <input type="submit" value="Submit" /> </form> </body> </html> Regardless of whether incorrect input is given, the data is still POSTed to the server and calculated on or a Server Side error is given. Am I correct in calling the function onClick? The validation essentially needs to be so that: - Student field contains a string - Score1, Score2, Score3 and Score 4 contain a number between 0 and 100 Any help is most appreciated, Cheers, Beetle. Hi, I am fairly new at Javascript but have some ability - though I can't figure this one out. I need a JavaScipt "IF Statement" that validates that a Text Field is in the format of 2 Letters then 2 Numbers. The field also has to contain a total of 4 characters no matter what. For example, every entry for that Text Field has to be in the following format: AB34 I would sincerely appreciate anyones help! I've just discovered (through trial and error) that if a variable is assigned a value without first being declared, it automatically has global scope, even if it is assigned inside a function. This is a pain in the butt because if you forget the var keyword, then suddenly ... whoops! You've got yourself a global variable! Is there any way that I can make javascript throw an exception if I fail to declare a variable before assigning a value to it? It would make things much easier, rather than having to hunt through increasingly complex functions to find that pesky unintentionally global variable. How do I fix the problem that autocomplete does not validate, I have heard before that there is a dirty way to do this but did not want to do this before, but now feel i must as my boss wants the site error free ! does anyone know how I do this ? Please see my Booking Form here http://www.n-v-m.co.uk/Booking.html The form is very nearly finished but I have no experience with JavaScript at all so I am hoping somebody can tell me how to do the finishing touches. All I require is: 1- On clicking the 'Submit order' button I would like the browser to check to see if the 'Is Vehicle roadworthy with full M.O.T.:' List/Menu is set to 'Yes' and if not it needs to return an alert stating it must be set to 'Yes' to proceed... Somebody kindly helped show me how to do the alert before so this is working, but, the problem at the moment is after clicking 'OK' to close the alert, the form is still submitted. At this point instead of the form being submitted I would just like the browser to return to the form. 2- There is a checkbox on the bottom of the form that states 'I agree with the Terms and Conditions'... To be able to proceed with a booking I need the customer to check the box... On clicking 'Submit order' if the box isn't checked I would like an alert to appear and the form not to be submitted. 3. When both the above criteria have been met and the form is ready to submit... I would like the browser to re-direct to http://www.n-v-m.co.uk/Thankyou.html which is a page I have already created on my server. Thanks for taking your time to read this... If it helps I have posted both my HTML and PHP codes below: Booking.html 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>National Vehicle Movements - Booking Form</title> <style type="text/css"> <!-- body { background-color: #1d255f; margin: 0px; padding: 0px; } #apDiv1 { position:absolute; width:487px; height:706px; z-index:auto; left: 50%; top: 433px; font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; text-align: center; textarea-align: center; background-position: center; margin-left: -244px; } --> </style> <script type='text/javascript'> function isValid() { var box = document.getElementById('Is Vehicle Roadworthy with Full M.O.T.'); if(box.value = 'no') { alert('The vehicle must be roadworthy with full M.O.T'); return false; } } </script> </head> <body> <div align="left"> <div id="apDiv1"> <form id="form1" name="form1" method="post" action="sendform.php" onsubmit='validatethis()'> <table width="400" border="0" align="center"> <tr> <td width="193" align="right">Company:</td> <td width="197" align="left"><input type="text" name="company" id="Company" /></td> </tr> <tr> <td align="right">Name:</td> <td align="left"><input type="text" name="name" id="Name" /></td> </tr> <tr> <td align="right">Phone Number:</td> <td align="left"><input type="text" name="phonenum" id="Phone Number" /></td> </tr> <tr> <td align="right">Email Address:</td> <td align="left"><input type="text" name="email" id="Email" /></td> </tr> <tr> <td align="right">Vehicle Make and Model:</td> <td align="left"><input type="text" name="vmam" id="Vehicle Make and Model" /></td> </tr> <tr> <td align="right">Vehicle Reg./Ref. No.:</td> <td align="left"><input type="text" name="vreg" id="Vehicle Reg." /></td> </tr> <tr> <td align="right">Collection Address including Postcode:</td> <td align="left"><textarea name="colladd" rows="4" id="Collection Address"></textarea></td> </tr> <tr> <td align="right">Collection Contact Name:</td> <td align="left"><input type="text" name="collconname" id="Collection Contact Name" /></td> </tr> <tr> <td align="right">Collection Contact Number:</td> <td align="left"><input type="text" name="collconnum" id="Collection Contact Number" /></td> </tr> <tr> <td align="right">Delivery Address including Postcode:</td> <td align="left"><textarea name="deladd" rows="4" id="Delivery Address"></textarea></td> </tr> <tr> <td align="right">Delivery Contact Name:</td> <td align="left"><input type="text" name="delconname" id="Delivery Contact Name" /></td> </tr> <tr> <td align="right">Delivery Contact Number:</td> <td align="left"><input type="text" name="delconnum" id="Delivery Contact Number" /></td> </tr> <tr> <td align="right">Collection Date/Time:</td> <td align="left"><input type="text" name="collectiondt" id="Collection Date/Time" /></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if possible please give a time window eg. '7th - 9th August' and we will arrange collection for you)</em></td> </tr> <tr> <td align="right">Delivery Date/Time:</td> <td align="left"><input type="text" name="deliverydt" id="Delivery Date/Time" /></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if possible please give a time window eg. '7th - 9th August' and we will arrange delivery for you)</em></td> </tr> <tr> <td align="right">Is Vehicle Taxed:</td> <td align="left"><select name="Taxed" id="Is Vehicle Taxed"> <option>Yes</option> <option selected="selected">No</option> </select></td> </tr> <tr> <td align="right">Is Vehicle roadworthy with full M.O.T.:</td> <td align="left"><select name="mot" id="Is Vehicle Roadworthy with Full M.O.T."> <option>Yes</option> <option selected="selected">No</option> </select></td> </tr> <tr> <td align="right">Billing Address:</td> <td align="left"><textarea name="billadd" rows="3" id="Billing Address"></textarea></td> </tr> <tr align="center"> <td colspan="2" valign="top"><em>(if same as collection or delivery address please enter 'collection' or 'delivery')</em></td> </tr> <tr> <td align="right">Your Ref./Order No. (if any):</td> <td align="left"><input type="text" name="custordnum" id="Customer Ref./Order No." /></td> </tr> <tr> <td align="right">Any additional comments:</td> <td align="left"><textarea name="addcom" rows="3" id="Any additional comments"></textarea></td> </tr> <tr align="center" valign="middle"> <td colspan="2"> <p> <input type="checkbox" name="checkbox" id="checkbox" /> I agree with the <u><a href="Terms.html">Terms and Conditions</a></u></strong></p> <p> </p></td> </tr> <tr align="center"> <td colspan="2"><input type="submit" name="button" id="button" value="Submit order" onclick="isValid()" /> <input type="reset" name="button2" id="button2" value="Reset form" /></td> </tr> </table> </form> </div> </div> <div align="center"><img src="images/Booking_03.jpg" width="680" height="1352" border="0" usemap="#Map" /> <map name="Map" id="Map"> <area shape="rect" coords="36,155,158,173" href="index.html" alt="Home" /> <area shape="rect" coords="29,174,151,189" href="Prices.html" alt="Prices" /> <area shape="rect" coords="475,191,578,206" href="mailto:info@n-v-m.co.uk" alt="Email us" /> </map> </div> </body> </html> sendform.php Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <BODY> <?php $Name = $_POST['name']; //senders name $to = "info@n-v-m.co.uk"; //recipient $subject = "Order from ".$_POST['company']." (".$_POST['name'].")"; //subject $message = $_POST['company']."|".$_POST['name']."|".$_POST['phonenum']."|".$_POST['email']."|".$_POST['vmam']."|".$_POST['vreg']."|".$_POST['colladd']."|".$_POST['collconname']."|".$_POST['collconnum']."|".$_POST['deladd']."|".$_POST['delconname']."|".$_POST['delconnum']."|".$_POST['collectiondt']."|".$_POST['deliverydt']."|".$_POST['Taxed']."|".$_POST['billadd']."|".$_POST['custordnum']."|".$_POST['addcom']; //mail body $from = "NVM Booking Form"; // $headers = "From: ".$from."\r\n"; //optional headerfields mail($to, $subject, $message, $headers); //mail command :) you can add any variable here... I know you have so many, but it is possible... if(mail) echo "Booking confirmed. Thank You!"; else echo "Sorry We Can't Proceed, Please Try After Some Time!"; ?> </BODY> </HTML> I am trying to make validation for a form but the bit I am stuck on now is: Code: <input class="submit" type="submit" value="Submit" id="submit" name="submit" onclick="return validate();" /> Do I have to add 'verify' instead of the 'validate' I mean is this a set thing in JS as I want it to go to the JavaScript code which is validate.js I should add that the form is XHTML and there is also a captcha with it. So I would not know how to add the onsubmit to the beginning of the form. Is there a y regular expression which we can use in JavaScript to validate URL? Or any other type of validation to validate URL which has http or https?
I am trying to create an onChange action that will validate that confirmation checkbox has been checked, and if not, popup an alert message and put the focus on the checkbox input and change the class of the container DIV to "highlight". Here is the form, with the 'onchange' trigger: Code: <form id="checkout" name="my_form" method="post" action="!---SCRIPT_NAME---" onsubmit="return validForm(this);"> <div id="verification" class="aligncenter required"> <input type="checkbox" id="verified" name="verified" value="" /> <label for="verified">YES</label>, the items and quantities shown above are correct.</div> <div class="required"><label for="name">Name:</label><input id="name" name="contactname" type="text" class="L" onchange="" /></div> <div class="required"><label for="company">Company Name:</label><input id="company" name="company" type="text" class="L" /></div> <div class="buttonRow"><input type="submit" name="VERIFY" class="btn red" value="Continue" /></div> </form> And here is my javascript code: Code: function verifyOrder() { if (document.my_form.verified.checked != "true") { alert("Please verify the contents of your order"); document.my_form.verified.focus(); getElementById('document.my_form.verification').className='highlight' return false; } } But this is not working and generates errors in firebug. What am I doing wrong? Thanks!! I have a group of checkboxes named "list[]". I want to validate that at least one is checked. How can I do this?
All, I have a page that has some checkboxes in it. I have the following function for that: Code: function checkbeforesubmit(field) { for (var i = 0; i < field.length; i++){ if(field[i].checked){ // if a field is checked form is submitted alert("You have checkboxes that are selected. Add the photos before you go to the next set of pictures!"); return false; } } return true; // if no fields are checked form not submitted } I then a link to go to the next page and I want to check to see if any checkboxes are selected before I go to the next page. I try and check this by doing this: Code: onClick="checkbeforesubmit(document.photos.elements['picbigid[]'])" It does the check and says that a checkbox is selected but will still go to the next page anyway. How can I stop it from going to the next page? Thanks! hi, I would to validate a textbox, and limit it to 3alphabets and 3 numbers. That is after the user have input 3 alphabets, he can only enter 3 numbers and nothing more. Can someone help me out? The below code works ok but need our help to get it perfect. I want the function to validate that after the "@" the user types "wendys.com". Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <meta name="GENERATOR" content="Microsoft FrontPage 4.0"> <meta name="ProgId" content="FrontPage.Editor.Document"> <title>New Page 1</title> <SCRIPT> function validateLP(theForm){ if(theForm.DM_Email){ var checkEmail =theForm.DM_Email.value; var invalidChars = " /:,;" if (checkEmail == "") { alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } if (checkEmail != "") { // can be empty for (i=0; i<invalidChars.length; i++) { // does it contain any invalid characters? var badChar = invalidChars.charAt(i) if (checkEmail.indexOf(badChar,0) > -1) { alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } } var periodPos1 =checkEmail.indexOf(".",1) // there must be one "." symbol var atPos = checkEmail.indexOf("@",periodPos1-1) // there must be one "." symbol before "@" var periodPos2 = checkEmail.indexOf(".",atPos) //periodPos2 = checkEmail.indexOf(".",atPos) if ( (atPos == -1) || (periodPos2 == -1)){ //return false alert("Please enter a valid Wendys DM email address."); theForm.DM_Email.style.backgroundColor='#FFFF99'; theForm.DM_Email.focus(); return false; } } } } </SCRIPT> </head> <body> <form method="POST" NAME="theForm" onSubmit="return validateLP(theForm)" action="--WEBBOT-SELF--"> <p><input type="text" name="DM_Email" size="20"></p> <p> </p> <p> </p> <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p> </form> </body> </html> Can someone please help, I don't understand why my code doesn't work?! I just want to check to see if a checkbox has been checked... Code: <script language="JAVASCRIPT" type="text/djs"> function checkCheckBoxes() { if (document.f1.Times[].checked == false { alert ('You didn\'t choose any of the checkboxes!'); return false; } else { return true; } } </script> <form onsubmit="return checkCheckBoxes();" action="add-booking-script.php" name="f1" method="post"> <input type="checkbox" name="Times[]" value="07:00:00"> 07:00 - 10:00<br /> <input type="checkbox" name="Times[]" value="10:00:00"> 10:00 - 13:00<br /> <input type="checkbox" name="Times[]" value="13:00:00"> 13:00 - 16:00<br /> <input type="checkbox" name="Times[]" value="16:00:00"> 16:00 - 19:00<br /> </form> Hello guys, this is my first post here, im a newbie in javascript and i need to limit a textbox to only be 1 or 0, I dont want to use a checkbox because i would like the users to really be typing. heres what i got: Code: <input name="test" type="text" onchange="validaten(this.value)" size="15" /> <script type="text/javascript"> function validaten(test) { if (test != 0); alert("Only 1 and 0 are allowed"); } </script> Can you please help me? I have this script to validate contact form fields. It works fine for checking that fields are not blank. I added the valid email code, which I copied from the w3schools web site. But, it does not work. I am confused about how to reference the email form field name. That is really the only thing I changed, that is, I added the frm.elements to the email variable. Can anyone please help? Thanks! Code: function validate_form(frm) { frm.elements.name.className = "input"; frm.elements.email.className = "input"; frm.elements.subject.className = "input"; frm.elements.comments.className = "input"; var errors=0; // // NAME cannot be blanks // if (isBlank(frm.elements.name.value)) { frm.elements.name.className = "inputreq"; errors++; } // // EMAIL ADDRESS cannot be blanks // if (isBlank(frm.elements.email.value)) { frm.elements.email.className = "inputreq"; errors++; } // // SUBJECT cannot be blanks // if (isBlank(frm.elements.subject.value)) { frm.elements.subject.className = "inputreq"; errors++; } // // COMMENTS cannot be blanks // if (isBlank(frm.elements.comments.value)) { frm.elements.comments.className = "inputreq"; errors++; } // // EMAIL ADDRESS appears invalid // if (validate_email(frm.elements.email.value,"Not a valid e-mail address!")==false) { alert("TEST"); frm.elements.email.focus(); return false; } // // Errors // if (errors>0) { alert("Please enter all fields!"); return false; } //No errors //frm.submit(); } function isBlank(value) { regexp = /^\s*$/ return (value==null || regexp.test(value)); } // Validate email address function validate_email(field,alerttxt) { with (field) { apos=value.indexOf("@"); dotpos=value.lastIndexOf("."); if (apos<1||dotpos-apos<2) {alert(alerttxt);return false;} else {return true;} } } I want to validate a select list that looks like the below select list. How can I do this when it is named "status[]". <select size='4' MULTIPLE name='status[]'> <option value='COMPLETE'>COMPLETE</option> <option value='ENTERED'>ENTERED</option> <option value='INSTALLED'>INSTALLED</option> </select> I need help please. I'm trying to validate when a user selects an item from the equipment select list they must select a reason code as to why they are ordering the item. This must work across all rows. Also the field to the left of the equipment select list should allow the user to key in the item # of the part and the select list automatically gets selected with the part. How the heck do I do this. I tried the functions I have included but they suck! Please help me Tracy Code: <script> function validateReason(){ var tr, i=1; while(tr=document.getElementById('Child'+(i++))){ var txtV=tr.getElementsByTagName('input')[0].value var selS=tr.getElementsByTagName('select')[0].selectedIndex; if(txtV.length>0&&selS==0){alert('If you enter a quantity you must select a reason!');return false} } } function change_uids(uid){ var uids = document.getElementById("uids"); for (var i=0; i<uids.options.length; i++){ if (uids.options[i].value == uid.value){ uids.options[i].selected = true; break; } } } </script> <form method="POST" onsubmit="return validateReason(this) ;" action="" name="theForm" > <table> <tr id='Child1'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='wic[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> <tr id='Child2'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='num[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> <tr id='Child3'> <td><input type = 'text' MAXLENGTH='3' style = 'width:40px'; class='textfield' name='quantity[]' ></td> <td><input type = 'text' MAXLENGTH='6' style = 'width:60px'; class='textfield' onkeyup='change_uids(this)' id='uid' name='wic[]' ></td> <td> <select size='1' STYLE='width: 270px' class='smallDrop' id='uids' name='itemid[]'> <option value='' > - Choose Equipment - </option> <option value='112233' > ZENTIH - </option> <option value='332244' > EMERSON - </option> <option value='0949' >LG</option> <option value='99623' >SONY</option> </select> </td> <td> <select size='1' STYLE='width: 130px' class='smallDrop' name='reason_codes[]'> <option value='' > - SET REASON - </option> <option value='BROKEN' >BROKEN</option> <option value='ENTERED' >ENTERED</option> <option value='SHORT' >SHORT</option> </select> </td></tr> </table> <input type="submit" value="SUBMIT" name="submit"> </form> |