TechMynd, Fresh Downloads and Latest Technology News, Stuff That Works | Downloads, Tips & Tricks, Softwares, Programming, Resources, IT, Computer, Resources, Freewares

Form Validation - Input Fields Text Changes at OnClick OnBlur OnFocus



We will be needing a js file and a page containing form input field to do this task.
What we are planning is, The input field contains default value. Onclick default value disappears and allows the user to insert text.
If the user types anything it remains there but if he does not write anything and clicks at next input field than the default value reappears in previous field.

JS file Code:

function remName(a, b){
if(a.value==b){
a.value='';
}else if(a.value==''){
a.value=b;
}else{
a.value=a.value;
}
}
 
function chkName(a, b){
if(a.value==''){
a.value=b;
}else{
a.value=a.value;
}
}

Two functions are controlling the event as above.

Call the js file in the page and define input fields and put some code like this.

Input Fields:

<font color="#ff0000"><code>&lt;input name="txtName" type="text" id="txtName" onfocus="remName(this, 'Name');" onblur="chkName(this, 'Name');" value="Name"&gt;
&lt;input name="txtEmail" type="text" id="txtEmail" value="Email" onfocus="remName(this, 'Email');" onblur="chkName(this, 'Email');"&gt;</code></font>

and so on…

Tags: , ,
Posted in: Forms, HTML, Java Script
Post's RSS » RSS 2.0
Post's Comments RSS » RSS 2.0

Related Posts


Post a Comment

Comment will appear here after approval, Thanks for patience

  Subscribe Via RSS
  Subscribe Via Email

Add to Technorati Favorites

Donate towards TechMynd web hosting Bill!

Advertisement