0

I have a search form:

    <form id="global_search">
      <input id="global_search_input" name="search_query" placeholder="Enter search text">
      <input id="global_search_button" type="submit" value="" onclick="slide_box_search(search_query); return false;" class="listings_box">
    </form>

and I want to display the results in a slide down div, pulling the results in via AJAX. I'm using codeigniter, so I want to pass the search query to the controller (as a url segment). The ajax and controller bit all works fine using Jquery and the load function, however I don't know how to get the search query from the input box to the function in the submit onclick = slide_box_search(search_query)?

I'm thinking it's probably something like $(this).val() but can't quite figure it out.

Thanks in advance!

1 Answer 1

4

Instead of this you need the value from the other input, like this:

$('#global_search_input').val();

Or overall:

slide_box_search($('#global_search_input').val()); return false;

It would be better to attach the event handler unobtrusively though, like this:

$(function() { //run when the DOM is ready
  $("#global_search_button").click(function() {
    slide_box_search($("#global_search_input").val()); 
    return false;        
  });
});

...and just remove your inline onclick altogether.

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

Comments

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.