Results 1 to 2 of 2

Thread: Passing user input to a jquery selector

  1. #1
    Join Date
    Aug 2010
    Posts
    86
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Passing user input to a jquery selector

    I'm creating a search page in a smartphone app, the search page accepts user input and then searches the app for a match and displays the results. For some reason the results come back as "undefined". I set up a jsfiddle to illustrate the problem here http://jsfiddle.net/tonybabb/Lvws4s0u/12/

    I did some previous testing with the app using Alert to display the variable and that seems to be OK, I also hard coded the search term in the jQuery statement and that seems to work also so I think the problem is replacing the hard coded search term with a variable in a jQuery statement. Unfortunately I couldn't get Alert to work in jsfiddle so I removed them.

    Thanks for any advice.

    Tony

  2. #2
    Join Date
    Aug 2010
    Posts
    86
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    Never mind, I figured it out. Not exactly sure why but the statement :
    Code:
    document.getElementById("searchResultsP").innerHTML = $( ".english:contains(" + $searchTerm + ")" ).html();
    was inserting a bunch of js code in the paragraph. The resolution was to do it in two steps, first get the search results in a variable and then insert the variable in the paragraph as shown below
    Code:
    var $searchResultsAlert = $( ".english:contains(" + $searchTerm + ")" ).html();
    document.getElementById("searchResultsP").innerHTML = $searchResultsAlert;

Similar Threads

  1. how to direct a user to a url using a user input
    By scottt in forum JavaScript
    Replies: 3
    Last Post: 10-26-2014, 11:06 AM
  2. Input Date Format and passing variables
    By ronchan in forum Dynamic Drive scripts help
    Replies: 0
    Last Post: 10-14-2008, 05:18 AM
  3. Replies: 0
    Last Post: 12-19-2007, 07:34 PM
  4. Replies: 1
    Last Post: 09-01-2006, 02:27 PM
  5. Help please! Calendar Script not passing input
    By rjbutterworth in forum Dynamic Drive scripts help
    Replies: 2
    Last Post: 03-27-2006, 08:33 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •