onclick event for textbox?

liunx

Guest
Hi

A stupid little question. I have a search form with a textbox. In that textbox I put the default value "Fill in username". (it has a light grey color). I want to clear the textbox when I click on it, for the first time.

Is there a way server sided or client side, that I can clear the textbox.text when i click it the first time?


<table>
<tr>
<td colspan="2" style="text-align:left; vertical-align:middle;"><span class="pageTitle">Search Users<br /><br /></span></td>
</tr>
<tr>
<td style="text-align:left; vertical-align:middle;"><asp:TextBox ID="txtusername" runat="server" Columns="40" ForeColor="#666666">Fill in username (email address)</asp:TextBox><asp:ImageButton ID="ImageButton1" ImageUrl="~/images/SearchSubmitArrow.gif" runat="server" /></td>
</tr>
</table>Yeah, I did that last time. It is javascript.

in your textbox control, you can try to put onFocus="clear_text();"

Then in the javascript:
function clear_text() {
document.myform.txtusername.value = "";
}

I did this in asp but I believe this works in your asp.net also.the asp.net textcontrol does not support the "onFocus" event :-(Your right, asp.net does not "support" the onFocus attribute. However, it will simply leave it in the tag and pass it on to the HTML page, where the JS engine will recognize and use the code correctly. You can use attributes that are not part of the asp.net tag without a problem, they are just left alone.

~ mellamokb.
 
Back
Top