0

I want to clear default value of a textbox with jquery.

@Html.TextBox("password", ***@Views.Resource.Password***, new { @class = "cssClass" })
3
  • How does the rendered html look like? Commented Dec 15, 2011 at 11:06
  • It looks like whatever in @Views.Resource.Password Commented Dec 15, 2011 at 11:08
  • This is not what the rendered html looks like, and because I have no experience with asp, I don't know how the result will look like. Ali's solution may work, but you should assign an id to it and use that instead. Commented Dec 15, 2011 at 11:11

2 Answers 2

3

use this solution :

$(function (){

    $("input.cssClass").val('');

});

or

$(document).ready(function(){

    $("input.cssClass").val('');

});
Sign up to request clarification or add additional context in comments.

2 Comments

I dont want to change css, @Views.Resource.Password shows some default text inside the textbox. When the textbox clicked I want the text to be cleared.
do you think this code will change your css? it is not correct dude, this code just change the value of the textbox
0

You could use a custom html helper to get the id of the texbox:

public static class HtmlHelperExtensions
{
    public static MvcHtmlString ClientIdFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression)
    {
        return MvcHtmlString.Create(htmlHelper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldId(ExpressionHelper.GetExpressionText(expression)));
    }
}

The you could say in the jQuery:

$("#@(Html.ClientIdFor(m => m.Password))").val("");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.