RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

help in validation by javascript

Join Date: Apr 2007
Location: Birmingham
Posts: 379
Reputation: Fungus1487 is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 38
Fungus1487's Avatar
Fungus1487 Fungus1487 is offline Offline
Posting Whiz

Re: help in validation by javascript

  #2  
Apr 30th, 2007
here you go

<script type='text/javascript'>
function isEmpty(elem, errMsg){
	if(elem.value.length == 0){
		alert(errMsg);
		elem.focus();
		return true;
	}
	return false;
}
</script>
<form>
Name : <input type='text' id='name'/>
<input type='button' 
	onclick="isEmpty(document.getElementById('name'), 'Please Enter a Value')"
	value='Check Field' />
</form>

obviously it will work the same with a textarea but i just ripped it out of some of my own code. hope this helps
When Autumn Falls [ http://www.whenautumnfalls.co.uk ] &&
Designdotworks [ http://www.designdotworks.co.uk ] Web / Graphic / Software Design
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 3:44 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC