Generally i saw any registration form the textboxes are filled with for example Enter first name or Enter Last name here like that how can i write like that. Is it javascript? can u tell me how can i write that like that help me thanks
You have to set the value property of the textbox to the desired text like
<input type="text" id="txt1" value="Enter text here" />
When input receives focus and is the value is the default one then clear the value. And if the user hasn't entered anything and when focus leaves the textbox put the default values back to the textbox.
Also make sure that you don't update database with the default value.
As you suggested yourself, you could use JavaScript called on the onload
event, something like:
<body onload="document.getElementById('firstName').value = 'Enter first name'" ...>
You could group multiple instructions in a function and just call that on onload
.
Or you could just set the value directly in the input:
<input type="text" id="firstName" name="firstName" value="Enter first name" />
What you want is a TextBoxWatermark. The AJAX Control Toolkit has one.
Also, here is an example of a custom ASP.NET Textbox Watermark.
EDIT: Example below is from link referenced above
Control Markup:
<asp:textbox id="txtSimpleSearch" runat="server"></asp:TextBox>
JS Functions:
function WatermarkFocus(txtElem, strWatermark) {
if (txtElem.value == strWatermark) txtElem.value = '';
}
function WatermarkBlur(txtElem, strWatermark) {
if (txtElem.value == '') txtElem.value = strWatermark;
}
Code Behind:
string strWatermarkSearch = "Search";
txtSimpleSearch.Text = strWatermarkSearch;
txtSimpleSearch.Attributes.Add("onfocus", "WatermarkFocus(this, '" + strWatermarkSearch + "');");
txtSimpleSearch.Attributes.Add("onblur", "WatermarkBlur(this, '" + strWatermarkSearch + "');");
Based on your comments to the post by phoenix you could try something like this:
<input type="text" value="Enter your name..." onfocus="CheckText(this, 'Enter your name...');" />
<script language="javascript">
function CheckText(e, text){
if(e.value == text){
e.value = '';
}
}
</script>