Results 1 to 2 of 2

Thread: Search trouble

  1. #1
    Join Date
    Apr 2009
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Search trouble

    hi, what i want to do is this:

    type something into a text field, if a div with a rel that is the same as the text field value show that div.

    Code:
    <script type="text/javascript">
    function search() {
    var search = document.getElementById('search').value;
    var results = document.getAttribute('rel');
    var resultsIf = results = search;
    if (resultsIf = true){
    results.style.display = "block";
    }
    </script>
    </head>
    <body>
    <div rel="go" style="border:0;display:none;">hello there!</div>
    <input type="text" id="search"><input type="button" onclick="search()">
    cheers

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Div in the document? So basically you type: box, and all divs with the rel="box" attribute and value display?

    Code:
    <script type="text/javascript">
    var searchRel = function(el){
      for(i=0;(a=document.getElementsByTagName('div')[i]);i++){
        if(el.value == a.getAttribute("rel")){ a.style.display = "block"; }
        if(el.value != a.getAttribute("rel")){ a.style.display = "none"; }
      }
    };  
    </script>
    <input type="text" name="search" onkeyup="searchRel(this);" />
    <div rel="lightblue" style="display:none;width:100px;height:200px;background:lightblue;">Hello</div><div rel="brown" style="display:none;width:500px;height:220px;background:brown;">How are you?</div><div rel="green" style="display:none;width:300px;height:620px;background:green;">Green!</div>
    You can try typing lightblue, brown, and green.
    Last edited by Nile; 05-17-2009 at 02:04 PM.
    Jeremy | jfein.net

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
  •