Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Feb 20, 2002

Trim the Contents of HTML Form Elements


To use this tip, the HTML form element which is required for Null Check should assign the title property some value concatenated with "C." For example:
 
<input type=text name=txtName title="C-Name">

On the submit tag, call the following function:
 
<input type=submit onClick="return CheckNull">

<script language=javascript>

function CheckNull()
{
	i=0
	for (i=0;i<document.frm.length;i++)
		{
		strValue= new String();
		strValue=document.frm.elements[i].title;

		if(strValue.length==0) {}
		else
				{
			Trim(document.frm.elements[i]);

			if(strValue.substr(0,1)=="C" &&
document.frm.elements[i].value.length==0)
				{
				alert("Enter The value  " _
+ strValue.substr(2,strValue.length))
				document.frm.elements[i].focus()
				return false;
				break;
			 }
			}
			}
}

function Trim(text)
	{
	while(text.value.charAt(0)==' ')
	text.value=text.value.substring(1,text.value.length )
	while(text.value.charAt(text.value.length-1)==' ')
	text.value=text.value.substring(0,text.value.length-1)

	}
</script>
Narender Saraswati
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap