Results 1 to 2 of 2

Thread: Searching my app for content

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

    Default Searching my app for content

    Good morning,

    I'm building a smartphone app that is essentially a talking Spanish phrasebook using topics where the user can find related English/ Spanish phrases for each topic.

    I would like to give my users the ability to search the app for English words/ phrases and display the English word/ phrase followed by up to 3 Spanish phrases. I think I could use the jQuery "contains" selector to select the English phrases, but I think I have two problems:
    1) How would I also select up to three Spanish phrases that immediately follow it?
    2) How would I copy the results (English/ Spanish phrases) to the search page?

    Below is a section of code showing a couple of English phrases one followed by two Spanish phrases and the other followed by one Spanish phrase

    Code:
    <div class="english"> 
    	          You are under arrest
    </div> <!-- End English -->	
    <div class="wrapper">
    	<a class="formal spanish" data-ignore="true" href="arrUnderArrestF.mp3">F: Está  bajo arresto</a>
    	<a class="informal spanish" data-ignore="true" href="arrUnderArrestI.mp3">I: Estás  bajo arresto</a>
    </div> <!-- End .wrapper -->
     <div class="english"> 
                  I have an arrest warrant
    </div> <!-- End English -->	
    <div class="wrapper">
    <a class="spanish" data-ignore="true" href="arrArrestWarrant.mp3">Tengo una orden de arresto</a>
    </div> <!-- End .wrapper -->
    Thanks in advance for any suggestions.

    Tony

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

    Default

    I've been trying to get this to work for several days without success, I'm probably missing something very obvious.

    Basically I see 3 problems - so far!
    1) I'm not able to replace a hard coded search term with a variable in a jQuery statement
    2) When the hard coded search runs it returns the correct phrase but also includes a comment from the original html
    3) It only returns one search result when it should be returning several

    For testing I have been entering "arrest" in the search box.Here's what I've got so far:
    Below is a section of the html content it is searching
    Code:
    <div class="english"> <!-- Start English -->
         You are under arrest
    </div> <!-- End English -->	
    <div class="wrapper">
    	<a class="formal spanish" data-ignore="true" href="arrUnderArrestF.mp3">F: Está  bajo arresto</a>
    	<a class="informal spanish" data-ignore="true" href="arrUnderArrestI.mp3">I: Estás  bajo arresto</a>
    </div> <!-- End .wrapper -->
     <div class="english"> <!-- Start English -->
                  I have an arrest warrant
    </div> <!-- End English -->	
    <div class="wrapper">
    <a class="spanish" data-ignore="true" href="arrArrestWarrant.mp3">Tengo una orden de arresto</a>
    </div> <!-- End .wrapper -->
    I have a Search page where the user enters their search term and the results of the search should be displayed, here's the code for the page
    Code:
    <div class="english">
        Search for words in English
    </div>
    <div class="spacer"></div>
    <input name="searchTxt" type="text" maxlength="32" id="searchTxt" class="searchField"/>
    <button onclick="searchApp()"> Search </button>
    <div class="spacer"></div>
    <div id="searchResultsDiv">
    <p id="searchResultsP">Search results go here</p>
    </div> <!-- /searchResultsDiv -->
    and here's the js with some comments added
    Code:
    function searchApp() {
    var $searchTerm = "";
    $searchTerm =  document.getElementById("searchTxt").value;
    alert ("$searchTerm is " + $searchTerm); // this displays the search term entered by the user and is working correctly
    alert("search 1 results " + $( ".english:contains($searchTerm)" ).html()); // this does not work, returns 'undefined'
    alert("search 2 results hard coded " + $( ".english:contains('arrest')" ).html()); // this works correctly - I just hard coded a search term
    var $searchResultsAlert = $( ".english:contains('arrest')" ).html();
    alert ("search 3 results hard coded are " + $searchResultsAlert);  // this works correctly
    // The next line should overwrite the paragraph on the search page with the search results
    document.getElementById("searchResultsP").innerHTML = $( ".english:contains('arrest')" ).value; // This does not work it returns 'undefined' in the paragraph
    
    } // /searchApp
    Thanks for any input you may have.

    Tony

Similar Threads

  1. searching for a javascript
    By bjf98 in forum Looking for such a script or service
    Replies: 1
    Last Post: 11-30-2007, 11:06 PM
  2. searching for [Lightbox]
    By For-Tomorrow in forum Looking for such a script or service
    Replies: 5
    Last Post: 10-14-2007, 11:13 PM
  3. Searching for script
    By compmom in forum Looking for such a script or service
    Replies: 4
    Last Post: 07-25-2007, 12:12 AM
  4. Searching for FAQ Script
    By DJ_Melody in forum Looking for such a script or service
    Replies: 1
    Last Post: 02-09-2007, 05:58 AM
  5. Searching the Archives
    By jscheuer1 in forum Dynamic Drive scripts help
    Replies: 7
    Last Post: 09-28-2006, 06:30 AM

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
  •