Niranjan
Niranjan

Reputation: 823

Error while retrieving value from multiline textbox using Jquery

I have a requirement where I have to validate for the empty text of a multiline textbox in aspx. I am using jquery for this purpose.

My aspx page would look like this:

<asp:TextBox runat="server" ID="txtClarification" ClientIDMode="Static" TextMode="MultiLine" Rows="8" Style="width: 780px;"></asp:TextBox>

and in my Jquery function:

var textbox = ('#txtClarification').val();
if (textbox.length == 0) {
    //do something
}

But the statement which I retrieve the textbox value throws error:

Microsoft JScript runtime error: Object doesn't support property or method 'val'

Is there any difference in retrieving the value from a Multiline textbox?

Upvotes: 1

Views: 936

Answers (1)

Andrew Whitaker
Andrew Whitaker

Reputation: 126072

Don't forget the $:

var textbox = $('#txtClarification').val();
//------------^
if (textbox.length == 0) {
    //do something
}

Also I'm not an ASP.NET expert, but you may need to specify ClientID for your selector to work.

Upvotes: 1

Related Questions