4

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);
}
1
  • You are right, sorry about that Commented Jul 25, 2013 at 12:41

1 Answer 1

3

How about something more direct:

var txtBoxValue = $('#txtSearch').val();
alert(txtBoxValue);
Sign up to request clarification or add additional context in comments.

5 Comments

this will find by ID, is it working for name Attribute as well?
@Damith, notice the markup, the id of the text box is txtSearch.
from the question input[name='searchValue'] , OP try to find input with name searchValue, I'm not the Down Voter :)
@Damith, and I'm letting the OP know there is a much better way. An id is specified, use it. Working up the DOM trying to find something then below is messy at best, especially when not necessary.
@Arianule, not a problem friend. I'm glad I could be of assistance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.