SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    l'Europe
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript to search in anchors?

    Hi,

    I have a div element on my page containing a result set, build with php out of a mysql-table. The data in one column are hyperlinks. Clicking on them opens a popup with more details (from the same database table).

    Eg.

    col 1 .....
    -------------------------
    ref. 2a69/63 ....
    ref. 8f56z/251 ....
    ...

    To search for records, I could do it in php... no problem. I was just wondering if it also could be done with javascript?
    In row 1, the value 63 is used to display the details in the popup.
    When there are a lot of rows, I could be ease to overlook one...
    If I named an anchor on each link with this value (eg. named "63" in row 1), could I use javascript to - when entered "251" somewhere - go to the anchor of the row named "251". I could open the popup immediately with the details (on entering "251"), but viewing more details isn't always needed... one could just look for the status of the record, being displayed in another column of that row...

    Thank you for any suggestion!

    Sincerly,
    Ann

  2. #2
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My suggestion:
    var links = document.getElementsByTagName("a");
    // and then loop through all links and check if the last part of href is equal to the number entered and, if a matching link is found, scroll into view

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    l'Europe
    Posts
    94
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for your suggestions, jofa!

    I've tried puzzling the following together;

    Code:
    <script type="text/javascript">
    function ShowRow() {
    /*var set through php after submitting a number */
    var ref="<? echo($ref); ?>";
    /* only last numbers of the reference */
    var comp=ref.substr(12,5);
    
    var links=document.getElementsByTagName("a");
    
    for (i=0; i < links.length; i++)
    {
    if (links.item(i).getAttribute("href").value == comp)
    {
    ***** scroll table row into div layer view ****
    }
    }
    }
    </script>
    
    <?php
    if (isset($ref)) {
    echo("<body onload='javascript:ShowRow();'>");
    } else {
    echo("<body>");
    }
    ?>
    Is this going in the right direction? I've found some information about "scrollHeight" etc., but I'm not sure how to use it for my if-statement?

    Thank you for any suggestions,

    Sincerly,

    Ann

  4. #4
    Sultan of Ping jofa's Avatar
    Join Date
    Mar 2002
    Location
    SvÝ■jˇ­
    Posts
    4,080
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •