Arianule
Arianule

Reputation: 9043

passing a textbox value to a javascript function asp.net

I am having a little difficulty with this one. Trying to pass a textBox value to a javascript function and get undefined instead.

Advice perhaps on how I can get this variable to the function

<input type="image" runat="server" id="btnSearchFunction" src="Images/searchIcon.png" name="image" onclick="SearchContent();" width="16" height="20" />
<input type="hidden" name="searchValue" value="<%#txtSearch.Value %>" />
<input type="text" runat="server" id="txtSearch" name="searchValue" class="input-medium search-query" placeholder="Search ..."/>

and this is the function I am trying to pass it to

function SearchContent() {
    var txtBoxValue = $(this).parent().find("input[name='searchValue']").val();
    alert(txtBoxValue);
}

Upvotes: 4

Views: 2752

Answers (1)

Mike Perrenoud
Mike Perrenoud

Reputation: 67898

How about something more direct:

var txtBoxValue = $('#txtSearch').val();
alert(txtBoxValue);

Upvotes: 3

Related Questions