Okay, I have two issues that are kind of one in the same. First off, I am trying to validate some forms I have. The form of validation I am using is from this link:
http://www.javascript-coder.com/html...lidation.phtml In my form, I have a few fields which are not required, but if a certain field has a value then another field would be required. For example, if the user input a number for 'mileage' then they should also be required to provide 'mileage_units'. I tried several techniques to get this to work, but none of them work. 'undefined' was my last attempt. I have tried != '' as well, but that also did not work. Secondly, I allow users to provide an image with this form. They can choose to upload an image from their local machine, or they can provide a remote URL of an image. What I want to do is integrate my validation to ensure they are not providing both of the image types. I tried to do some of the custom validation the script uses, but to no avail. I am pretty new to js although I do kind of understand it, just new to the object oriented aspect. Along with this, I am unsure of how to code the checks to see which image was provided. Any PHP suggestions for that would also be warranted. Below is my generated source of the form as well as the js validation following....any help would be greatly appreciated! Code: ---------
Year [Required] Select Year 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008
Make [Required] Select Make ------ACAcuraAixamAlfa-RomeoAsiaAston-MartinAudiAustinBentleyBMWBristolCadillacCaterhamC hevroletChryslerCitroenDaewooDaihatsuDaimlerDatsun DelorianDodgeFerrariFiatFordFSOGinettaGriffonHillm anHMCHondaHummerHyundaiISOIsuzuJaguarJeepJensenKia LadaLamborghiniLanciaLand RoverLexusLigierLincolnLotusMarcosMaseratiMaybachM azdaMcLarenMercedes-BenzMGMicrocarMiniMitsubishiMorganMorrisNissanNobl eOpelPaganiPantherPeroduaPeugeotPontiacPorscheProt onReliantRenaultRileyRolls RoyceRoverSaabSaoSeatSingerSkodaSmartSsangYongSuba ruSunbeamSuzukiTalbotTataToyotaTriumphTVRUltimaVau xhallVolkswagenVolvoWestfieldYugo Not Listed? Click
Here Model [Required] dol.printOptions("model_id") Not Listed? Click
Here Engine Type Select Engine Type ------8 Cylinder Naturally8 Cylinder Forced Induction6 Cylinder Naturally6 Cylinder Forced Induction4 Cylinder Naturally4 Cylinder Forced Induction
Color Mileage Select Mileage Type ------ Miles Kilometers
Purchased Price Currency: Select Currency ------GBPUSDEURCADYEN
Description Image Attachments
You may attach an image.
Maximum file size : 1024 kbytes
Maximum resolution : 1024 Enter a URL to an online image Description var frmvalidator = new Validator("add_vehicle"); var frm = document.forms["add_vehicle"]; frmvalidator.addValidation("made_year","req","Plea se select a year."); frmvalidator.addValidation("made_year","dontselect =0","Please select a year."); frmvalidator.addValidation("make_id","req","Please select a make."); frmvalidator.addValidation("make_id","dontselect=0 ","Please select a make."); frmvalidator.addValidation("make_id","dontselect=1 ","Please select a make."); frmvalidator.addValidation("model_id","req","Pleas e select a model."); frmvalidator.addValidation("color","regexp=^[A-Za-z]{1,20}$","Color must consist of letters only and have a maximum of 20 characters."); frmvalidator.addValidation("mileage","numeric","Mi leage must be a numeric value."); if(frm.mileage.value != undefined) { frmvalidator.addValidation("mileage_units","req"," Please select a mileage unit."); frmvalidator.addValidation("mileage_units","dontse lect=0","Please select a mileage unit."); } frmvalidator.addValidation("price","numeric","Pric e must be a numeric value."); if(frm.price.value != undefined) { frmvalidator.addValidation("currency","req","Pleas e select a currency."); frmvalidator.addValidation("currency","dontselect= 0","Please select a currency."); } frmvalidator.addValidation("comments","maxlen=500" ,"Description must be less than 500 characters."); ---------
More...