Jump to content

Expert Format


user4fun
 Share

Recommended Posts

How difficult is it to set up a form like the high qulaity ones you see, When an error occures for missing data or invalid entry it would highlight it in red, or show the form again with the other field full and the one that is wrong has a text beside it that shows up.I dont want to make a seperate error form for every field. There might be a bunch of field, possible 15.

Link to comment
Share on other sites

You mean form validation? Error trapping is for handling runtime errors.That form of smooth validation is likely to be done client-side, with JavaScript. It would be easy to have a <span> tag next to each form field that gets tested onsubmit of the form and then if invalid the JS script would write something int othe tag. A simple one-filed example:

<script type="text/javascript">	function validate() {		error = false;		form = document.getElementById('form');		if (form.name == "") {			document.getElementById('name_error').innerHTML = "Please enter a valid name";			error = true;		}		return error;	}	function clearelement(ele) {		document.getElementById(ele).innerHTML = "";	}</script><form id="form" method="post" action="#" onsubmit="return validate()">Name: <input type="text" name="name" onfocus="clearelement('name_error')" /><span id="name_error"></span>

</form>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...