Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Nov 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Javascript revealer

    Hi,

    I'm quite new to Javascript but I decided to learn it.
    I want to make a function but I can't get hold of the right stuff to do. That's why I ask for your help!

    So I have got a <div> with many hidden <p>s. I want to make my script so that when a form input (text) is being written by the user (so onKeyUp), it reveals those paragraphs which have got the kind of text in them that's in the form input box.

    So for example:
    - the box is empty -> all paragraphs are hidden
    - the box has got "a" in it -> the javascript searches all paragraphs and makes those visible which paragraphs have the letter 'a' in them anywhere, and leaves the other paragraphs hidden.
    - the box has got "are" in it -> the script (or the function) searches the paragraph for the word "are" and shows those whcih have got it in them.

    I know how to make a paragrah hidden and visible, I also know how to set up the event with the form box to call the function...

    My problem is that I don't know how to et up the search in the particular paragraphs and how to get their ID perhaps... Once I had their ID I could make them visible.

    So my question is... Is there a way to search text in particular paragrah and if the search positive get their IDs? Or is it possible to search for IDs?

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,027
    Thanks
    203
    Thanked 2,539 Times in 2,517 Posts
    It is quite remarkable how beginners always seem to want the oddest and most outlandish things.

    I see many problems here. The user types "a" and all the paras containing the letter a (such as along) are revealed. He then types "r", and at once all those paras which do not contain "ar" are hidden again.

    And do you mean whole words or embedded words? If I type "fat" do I get "father"? Which is then hidden again when I go on to type "fatter"? Sounds a total mess to me.

    I think you should think this through and ask yourself why you want to do this. It will certainly drive people away from your site. If you are trying to devise some sort of search feature, then that should be done server-side.


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 11-16-2010 at 06:46 PM. Reason: Correction

  • #3
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,567
    Thanks
    78
    Thanked 4,385 Times in 4,350 Posts
    FWIW, if you still MUST do what you described, it's nearly trivial.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    javascript autocomplete

    http://www.somacon.com/p241.php


  •  

    Posting Permissions

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