Shadeplay23 Posted January 14, 2008 Share Posted January 14, 2008 Hello,I would like to know how to make a form required, so that if the user types in the wrong answer, then a pop-up message will appear saying that they need to fill that in. Link to comment Share on other sites More sharing options...
Guest FirefoxRocks Posted January 14, 2008 Share Posted January 14, 2008 I think you do that with JavaScript. You can verify if the field has an acceptable answer, then show a message or alert box or do something if it doesn't. Link to comment Share on other sites More sharing options...
emicha Posted January 14, 2008 Share Posted January 14, 2008 <!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=iso-8859-1" /> <title>Untitled Document</title> <script type="text/javascript" language="javascript"> function check() { var elem = document.getElementById('c1'); if(elem.value == 123) { alert('Right answer'); } else { alert('Wrong answer'); } } </script> </head> <body> <input type="text" id="c1" value="123" /> <input type="submit" onclick="check();" /> </body></html> Look at this. This is not a secure way to do this kind of check. Use AJAX or only PHP but in this case the page should be reloaded automatically. Link to comment Share on other sites More sharing options...
vchris Posted January 14, 2008 Share Posted January 14, 2008 Yeah the most secure way to make form fields required is with a server-side language such as PHP, ASP, ColdFusion... since a user cannot override these pages when properly coded. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.