code isn't working. <script type="text/javascript"> <!-- function validate(){ if ((document.example2.naming.value=="")|| (document.example2.feed.value=="")){ .alert ("You must fill in all of the required .fields!") .return false.} else return true } //--> </script> <form name="example2"onsubmit="return validate()"> <input type="text" size="20" name="naming"> <strong>Feedback please: (*required)</strong> <textarea name="feed" rows="3" cols="25"></textarea> <strong>Your home address (*NOT required)</strong> <input type="text" size="35" name="address"> <input type="submit" name="B1" value="Submit"> </form>
Hello! That should work... Make sure that you close all html tags i.e. <input type="text" size="20" name="naming" />. Also use semi colon in JavaScript. And use [ HTML ] when posting to forum. <!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> <title>untitled</title> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <script type="text/javascript"> function validate() { if ((document.example2.naming.value=="") || (document.example2.feed.value=="")) { alert ("You must fill in all of the required fields!"); return false; } return true; } </script> </head> <body> <form name="example2"onsubmit="return validate()"> <input type="text" size="20" name="naming" /> <strong>Feedback please: (*required)</strong> <textarea name="feed" rows="3" cols="25"></textarea> <strong>Your address (*NOT required)</strong> <input type="text" size="35" name="address" /> <input type="submit" name="B1" value="Submit" /> </form> </body> </html> HTML: