Imoddedu Posted April 12, 2009 Share Posted April 12, 2009 Can anybody show me an example of using JavaScript to verify forms? Like setting one of the form values equal to a JavaScript variable? Link to comment Share on other sites More sharing options...
jeffman Posted April 12, 2009 Share Posted April 12, 2009 Grossly oversimplified: function validate(form){ var u = form.user.value; var p = form.pw.value; if ((u == "")||(p == "")) { document.getElementById('text').innerHTML = "<p>Please complete username and password fields.<\/p>"; return false; } return true;}function init(){ document.forms[0].user.focus(); document.forms[0].onsubmit = function () { return validate(this); }}window.onload = init;* * *<form action="" method="post"> <input type="text" name="user"> <input type="password" name="pw"></form><div id="text"></div> Link to comment Share on other sites More sharing options...
Imoddedu Posted April 13, 2009 Author Share Posted April 13, 2009 Awesome dude, that looks good! Thanks for showing me. Link to comment Share on other sites More sharing options...
jeffman Posted April 13, 2009 Share Posted April 13, 2009 Awesome dude, that looks good! Thanks for showing me.No sweat. I lifted it (with a few changes) right out of a current project. I literally had login code open on my screen when you posted. Your good fortune! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.