Jump to content

Javascript And Forms


Imoddedu

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...