Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2008
    Posts
    291
    Tokens
    0

    Default What is wrong with this code?

    I type in my Username, which is shown below, however it doesnt update with a profile link, or username for that matter.


    <?php

    session_start();

    include('includes/db_connect.php');

    $username=$_SESSION['username'];

    $fetch = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '$username'"));



    if ( isset($_GET['search']) )

    {

    $find_username = mysql_escape_string($_GET['search']);

    $where = array();



    switch($_GET['where'])

    {

    case 1:

    $find_username = '%' . $find_username . '%';

    break;

    case 2:

    $find_username = $find_username . '%';

    break;

    case 3:

    $find_username = '%' . $find_username;

    break;

    case 4:

    $find_username = $find_username;

    break;

    }



    switch($_GET['status'])

    {

    case 2:

    $status = 'Alive';

    break;

    case 3:

    $status = 'Dead';

    break;

    default:

    $status = '';

    }

    if ( !empty($status) )

    $where[] = "`status` = '$status'";



    if ( !empty($_GET['ranks']) )

    {

    $ranks = split(';', mysql_escape_string($_GET['ranks']));

    for($i=0, $len = count($ranks); $i<$len; ++$i)

    {

    $ranks[$i] = "'".$ranks[$i]."'";

    }

    $strRanks = join(',', $ranks);

    $where[] = "`rank` IN ($strRanks)";

    }



    switch($_GET['order'])

    {

    case 2:

    $orderfield = '`date`';

    case 3:

    $orderfield ='rankpoints';

    default:

    $orderfield = 'username';

    }



    switch($_GET['orderby'])

    {

    case 2:

    $ordeby = 'DESC';

    default:

    $orderby = 'ASC';

    }



    $order = "ORDER BY $orderfield $orderby";



    $result = mysql_query("SELECT * FROM `users` WHERE `username` LIKE '%$find_username%'" . (count($where) > 0 ? ' AND ' . join(' AND ', $where) : '') . ' ' . $order);

    $return = "<table width=55% border=1 cellpadding='2' cellspacing=0 align='center' class='thinline'>

    <tr height='22' class='topic'>

    <td colspan='5' align='center' class='topic'>Users Found</td>

    </tr>

    <tr height='22' class='topic'>

    <td class=tip width='27'>O</td>

    <td class=tip width='5'>Friend</td>

    <td width='45%' class=tip><center><font color=white><b>Username</font></td>

    <td width='20%' class=tip><center><font color=white><b>Rank</b></font></td>

    <td width='17%' class=tip><center><font color=white><b>Status</b></font></tr>";



    while($row = mysql_fetch_object($result))

    {



    if ($row->crew=="0"){ $crew="None"; }else{ $crew=$row->crew; }



    $checkf = mysql_num_rows(mysql_query("SELECT * FROM friends WHERE person='$username' AND username='$row->username' AND type='Blocked'"));

    if($fetch->tester == "1"){ $reg = " <a href='javascript: ;' onclick=\"modal('prof2.php?viewuser=$row->username','<div class=\'header1\'>$row->username\'s Profile</div>','950','600');'>$row->username</a>"; }elseif($fetch->tester == "0"){ $reg = " <a href='profile.php?viewuser=$row->username'>$row->username</a>"; }

    $return .= "

    <tr height='22' background='>
    <td class=tableborder><b>$reg</b></td>

    <td class=tableborder><b><center>$row->rank</b></td>

    <td class=tableborder><b><center>$row->status</b></td>

    </tr>

    ";

    }



    $return .= " </table> ";



    //url = this.url + "search=" + this.searchOptUsername + "&where=" + this.searchOptWhere + "&status=" + this.searchOptStatus + "&order=" + this.searchOptOrderWhat + "&orderby=" + this.searchOptOrderBy + "&ranks=" + this.searchOptRank;



    echo $return;



    exit;

    }



    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>



    <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <meta name="author" content="vladykx" />



    <link rel="stylesheet" href="includes/in.php" type="text/css">

    <script type="text/javascript" src="ajaxSuggest.js"></script>


    <script type="text/javascript">

    function modal (page,title,width,height) {
    parent.passModal(page,title,width,height);
    return false;
    }

    </script>

    <title>Find User</title>

    <style type="text/css">
    <!--
    .style1 {color: #333333}
    .style2 {color: #666666}
    -->
    </style>
    </head>



    <body>



    <table width="100%" border="0" cellspacing="0" cellpadding="0">

    <tr>

    <td width="62%" align="center" valign="top"><table width="700" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="black" class="thinline">

    <tr>

    <td class="topic" colspan="6" height="<?php if($fetch->layout == "1"){ echo"20"; }else{ echo"29"; }?>"><center class="bold">

    Find Gangster

    </center></td>
    </tr>

    <tr>

    <td width="18%" bordercolor="#000000" class="tableborder">Username:</td>

    <td colspan="2" bordercolor="#000000" class="tableborder"><input type="text" id="ajaxSuggestElement" class="textbox" /></td>
    <td width="15%">Account status:</td>
    <td width="33%" colspan="2"><select name="type" class='input' onchange="ajaxSuggest.searchOptStatus=this.value; ajaxSuggest.doSuggest();">
    <option value="1">Any</option>
    <option value="2">Alive</option>
    <option value="3">Dead</option>
    </select> </td>
    </tr>

    <tr>

    <td width="18%" align="left">Position of criteria:</td>

    <td align="left" colspan="2"><select name="searchtype" class='input' onchange="ajaxSuggest.searchOptWhere=this.value; ajaxSuggest.doSuggest();">

    <option value="1">Anywhere</option>

    <option value="2">Beginning of the username</option>

    <option value="3">End the username</option>

    <option value="4">Full username</option>

    </select> </td>
    <td width="15%">Order by:</td>
    <td colspan="2"><select name="order" class='input' onchange="ajaxSuggest.searchOptOrderWhat=this.valu e; ajaxSuggest.doSuggest();">
    <option value="1">Name</option>
    <option value="2">Sign up</option>
    <option value="3">Rank</option>
    </select>
    <select name="orderby" class='input' onchange="ajaxSuggest.searchOptOrderBy=this.value; ajaxSuggest.doSuggest();">
    <option value="1">Ascending</option>
    <option value="2">Descending</option>
    </select> </td>
    </tr>

    <!-- <tr>

    <td valign="middle" bordercolor="#000000" colspan="3" class="tableborder" align="center"><input type="submit" class="custombutton" value="Search GB!" id="user_button6" name="user_button"/></td>

    </tr>-->

    </table></td>


    </tr>
    </table>

    <br />

    <div class="style1" id="search-results">
    <div align="center" class="style2">Search for a username in the box and it will update automatically.</div>
    </div>
    </body>

    </html>





    I type in my Username, which is shown below, however it doesnt update with a profile link, or username for that matter.




    Last edited by -Adam; 04-08-2010 at 04:53 PM.

  2. #2
    Join Date
    Apr 2010
    Location
    Newcastle
    Posts
    655
    Tokens
    50

    Default

    Can you re-post the code within PHP tags, then post ajaxsuggest.js within CODE tags.

  3. #3
    Join Date
    Oct 2007
    Posts
    824
    Tokens
    71

    Latest Awards:

    Default

    line 234: no end tag.
    line 308: bordercolor is not an attribute
    Vouches
    [x][x]

  4. #4
    Join Date
    Feb 2008
    Posts
    291
    Tokens
    0

    Default

    So how would I fix this?

    EDIT:

    PHP:

    PHP Code:
    <?php

    session_start
    ();

    include(
    'includes/db_connect.php');

    $username=$_SESSION['username'];

    $fetch mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE `username` = '$username'"));



    if ( isset(
    $_GET['search']) )

    {

        
    $find_username mysql_escape_string($_GET['search']);

        
    $where = array();



        switch(
    $_GET['where'])

        {

        case 
    1:

            
    $find_username '%' $find_username '%';

            break;

        case 
    2:

            
    $find_username $find_username '%';

            break;

        case 
    3:

            
    $find_username '%' $find_username;

            break;

        case 
    4:

            
    $find_username $find_username;

            break;

        }



        switch(
    $_GET['status'])

        {

        case 
    2:

            
    $status 'Alive';

            break;

        case 
    3:

            
    $status 'Dead';

            break;

        default:

            
    $status '';

        }

        if ( !empty(
    $status) )

        
    $where[] = "`status` = '$status'";



        if ( !empty(
    $_GET['ranks']) )

        {

            
    $ranks split(';'mysql_escape_string($_GET['ranks']));

            for(
    $i=0$len count($ranks); $i<$len; ++$i)

            {

                
    $ranks[$i] = "'".$ranks[$i]."'";

            }

            
    $strRanks join(','$ranks);

            
    $where[] = "`rank` IN ($strRanks)";

        }

      

      switch(
    $_GET['order'])

      {

        case 
    2:

            
    $orderfield '`date`';

        case 
    3:

            
    $orderfield ='rankpoints';

        default:

            
    $orderfield 'username';

      }

      

      switch(
    $_GET['orderby'])

      {

        case 
    2:

            
    $ordeby 'DESC';

        default:

            
    $orderby 'ASC';

      }

      

      
    $order "ORDER BY $orderfield $orderby";



      
    $result mysql_query("SELECT * FROM `users` WHERE `username` LIKE '%$find_username%'" . (count($where) > ' AND ' join(' AND '$where) : '') . ' ' $order);

      
    $return "<table  width=55%  border=1 cellpadding='2' cellspacing=0 align='center' class='thinline'>

          <tr height='22' class='topic'>

            <td colspan='5' align='center'  class='topic'>Users Found</td>

            </tr>

          <tr height='22' class='topic'>

            <td  class=tip width='27'>O</td>

            <td class=tip width='5'>Friend</td>

            <td width='45%' class=tip><center><font color=white><b>Username</font></td>

        <td width='20%' class=tip><center><font color=white><b>Rank</b></font></td>

        <td width='17%' class=tip><center><font color=white><b>Status</b></font></tr>"
    ;

      

      while(
    $row mysql_fetch_object($result))

      {

      

          if (
    $row->crew=="0"){ $crew="None"; }else{ $crew=$row->crew; } 

            

            
    $checkf mysql_num_rows(mysql_query("SELECT * FROM friends WHERE person='$username' AND username='$row->username' AND type='Blocked'"));

              if(
    $fetch->tester == "1"){ $reg " <a href='javascript: ;' onclick=\"modal('prof2.php?viewuser=$row->username','<div class=\'header1\'>$row->username\'s Profile</div>','950','600');'>$row->username</a>"; }elseif($fetch->tester == "0"){ $reg " <a href='profile.php?viewuser=$row->username'>$row->username</a>"; }

        
    $return .= "

        <tr height='22' background='> 
              <td class=tableborder><b>
    $reg</b></td>

              <td class=tableborder><b><center>
    $row->rank</b></td>

              <td class=tableborder><b><center>
    $row->status</b></td> 

            </tr>

    "
    ;

      }

      

      
    $return .= "  </table> ";

      

      
    //url = this.url + "search=" + this.searchOptUsername + "&where=" + this.searchOptWhere + "&status=" + this.searchOptStatus + "&order=" + this.searchOptOrderWhat + "&orderby=" + this.searchOptOrderBy + "&ranks=" + this.searchOptRank;

      

      
    echo $return;

      

      exit;

    }



    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <html>



    <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

    <meta name="author" content="vladykx" />



    <link rel="stylesheet" href="includes/in.php" type="text/css">

    <script type="text/javascript" src="ajaxSuggest.js"></script>


    <script type="text/javascript">

    function modal (page,title,width,height) {
        parent.passModal(page,title,width,height);
        return false;
    }

    </script>

    <title>Find User</title>

    <style type="text/css">
    <!--
    .style1 {color: #333333}
    .style2 {color: #666666}
    -->
    </style>
    </head>



    <body>



    <table width="100%" border="0" cellspacing="0" cellpadding="0">

      <tr>

        <td width="62%" align="center" valign="top"><table width="700" border="0" align="center" cellpadding="2" cellspacing="0" bordercolor="black" class="thinline">

          <tr>

            <td class="topic" colspan="6" height="<?php if($fetch->layout == "1"){ echo"20"; }else{ echo"29"; }?>"><center class="bold">

                Find Gangster

            </center></td>
          </tr>

          <tr>

            <td width="18%" bordercolor="#000000" class="tableborder">Username:</td>

            <td colspan="2" bordercolor="#000000" class="tableborder"><input type="text" id="ajaxSuggestElement" class="textbox" /></td>
            <td width="15%">Account status:</td>
            <td width="33%" colspan="2"><select name="type" class='input' onchange="ajaxSuggest.searchOptStatus=this.value; ajaxSuggest.doSuggest();">
                <option value="1">Any</option>
                <option value="2">Alive</option>
                <option value="3">Dead</option>
              </select>        </td>
          </tr>

          <tr>

            <td width="18%" align="left">Position of criteria:</td>

            <td align="left" colspan="2"><select name="searchtype" class='input' onchange="ajaxSuggest.searchOptWhere=this.value; ajaxSuggest.doSuggest();">

                <option value="1">Anywhere</option>

                <option value="2">Beginning of the username</option>

                <option value="3">End the username</option>

                <option value="4">Full username</option>

              </select>        </td>
            <td width="15%">Order by:</td>
            <td colspan="2"><select name="order" class='input' onchange="ajaxSuggest.searchOptOrderWhat=this.value; ajaxSuggest.doSuggest();">
                <option value="1">Name</option>
                <option value="2">Sign up</option>
                <option value="3">Rank</option>
              </select>
                <select name="orderby" class='input' onchange="ajaxSuggest.searchOptOrderBy=this.value; ajaxSuggest.doSuggest();">
                  <option value="1">Ascending</option>
                  <option value="2">Descending</option>
                </select>        </td>
          </tr>

          <!--    <tr>

            <td valign="middle" bordercolor="#000000" colspan="3" class="tableborder" align="center"><input type="submit" class="custombutton" value="Search GB!" id="user_button6" name="user_button"/></td>

        </tr>-->

        </table></td>

        
      </tr>
    </table>

    <br />

    <div class="style1" id="search-results">
      <div align="center" class="style2">Search for a username in the box and it will update automatically.</div>
    </div>
    </body>

    </html>
    AjaxSuggestions.js

    PHP Code:
    // ---
    function updateRanksArray(objCheckBox)
    {
        
    }

    // ---
    var ajaxSuggestions = {
        
    // Extra
        
    searchOptWhere1,
        
    searchOptStatus1,
        
    searchOptOrderWhat1,
        
    searchOptOrderBy1,
        
    searchOptRank: [],
        
    ajaxSuggestionElementnull,
        
    // Settings
        
    elmIdToPresentResultsIn "search-results",
        
    elmIdResultsContainer "search-result-suggestions",
        
    charactersBeforeSearch 2,
        
    timeBeforeSuggest 200// In milliseconds
        
    sameWidthAsInputElm false,
        
    offsetLeft0,
        
    offsetTop 0,
        
    urlExt "search=",
        
    addSearchTermToQueryString true,
        
    addKeyNavigationEvents false,
        
    hideResultsOnDocumentClick false,
        
    itemClassName "item",
        
    itemSelectedClassName "selected",
        
    itemInsertValueIntoInputClassName "choose-value",
        
    itemInsertValueSetFocusToInput false,
        
    hideResultsWhenInsertValueIsSelected false,
        
    itemSeparator ";",
        
    turnAutoCompleteOff true,
        
    // Object properties
        
    xmlHttp null,
        
    elements : [],
        
    timer null,
        
    currentElm null,
        
    currentKeyEvent null,
        
    suggestionsForElm null,
        
    elmToPresentResultsIn null,
        
    elmResultsContainer null,
        
    suggestions : [],
        
    resultIndex 0,
        
    selectedItem : -1,
        
    resultsAreVisible true,
        
    valueAddedFromResultsListToInput false,
        
        
    init : function (){
            
    this.xmlHttp this.createXmlHttp();
            if(
    this.xmlHttp){
                if(
    typeof document.getElementsByClassName != "function"){
                    
    document.getElementsByClassName this.elmByClass;
                }
                
    this.elements document.getElementsByClassName("ajax-suggestion""input");
                
    this.applyEvents();
                
    this.elmToPresentResultsIn document.getElementById(this.elmIdToPresentResultsIn);
                
    this.elmResultsContainer document.getElementById(this.elmIdResultsContainer);
                if(
    this.addKeyNavigationEvents){
                    
    this.addEvent(document"keydown"this.preventDefaultForArrowKeys);
                    
    this.addEvent(document"keypress"this.preventDefaultForArrowKeys);
                    
    this.addEvent(document"keyup"this.navigateResults);
                }
                if(
    this.hideResultsOnDocumentClick){
                    
    this.addEvent(document"click"this.clearResultsElement);
                }
            }
        },
        
        
    createXmlHttp : function (){
            
    this.xmlHttp null;
            if(
    typeof XMLHttpRequest != "undefined"){
                
    this.xmlHttp = new XMLHttpRequest();
            }
            else if(
    typeof window.ActiveXObject != "undefined"){
                try {
                    
    this.xmlHttp = new ActiveXObject("Msxml2.XMLHTTP.4.0");
                }
                catch(
    e){
                    try {
                        
    this.xmlHttp = new ActiveXObject("MSXML2.XMLHTTP");
                    }
                    catch(
    e){
                        try {
                            
    this.xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch(
    e){
                            
    this.xmlHttp null;
                        }
                    }
                }
            }
            return 
    this.xmlHttp;
        },
        
        
    applyEvents : function (){
            var 
    element;
            for(var 
    i=0i<this.elements.lengthi++){
                
    element this.elements[i];
                
    this.ajaxSuggestionElement element;
                if(
    this.turnAutoCompleteOff){
                    
    element.setAttribute("autocomplete""off");
                }
                
    this.addEvent(element"keyup"this.startSuggestionsTimer);
                if(
    this.hideResultsOnDocumentClick){
                    
    this.addEvent(element"click"this.preventInputClickBubbling);
                }
            }
        },
        
        
    startSuggestionsTimer : function (evt){
            
    clearTimeout(ajaxSuggestions.timer);
            
    ajaxSuggestions.currentElm = (/input/i.test(this.nodeName))? this evt.srcElement;
            
    ajaxSuggestions.currentKeyEvent evt.keyCode;
            
    ajaxSuggestions.timer setTimeout("ajaxSuggestions.getSuggestions()"ajaxSuggestions.timeBeforeSuggest);
        },
        
        
    startSuggestionsTimerNew : function (){
            
    clearTimeout(this.timer);
            
    //ajaxSuggestions.currentElm = (/input/i.test(this.nodeName))? this : evt.srcElement;
            
    this.currentElm this.ajaxSuggestionElement;
            
    this.currentKeyEvent 13;
            
    this.getSuggestions();
            
    console.log("startSuggestionsTimerNew()");
            
    //this.timer = setTimeout("ajaxSuggestions.getSuggestions()", this.timeBeforeSuggest);
        
    },
        
        
    getSuggestions : function (){
            var 
    value this.currentElm.value;
            
    console.log(value);
            if(!/
    13|27|37|39/.test(this.currentKeyEvent)){
                var 
    url this.currentElm.className.replace(/.*url-([\w\/\?\.-]+).*/, "$1");
                
    console.log(url);
                if(!
    this.valueAddedFromResultsListToInput){
                    
    ajaxSuggestions.clearResults(true);
                }
                if(
    value.length this.charactersBeforeSearch && url.length 0){
                    
    console.log("makeSuggestionCall");
                    
    this.makeSuggestionCall(valueurl);
                }
                else if(
    value.length == || !this.valueAddedFromResultsListToInput){
                    
    ajaxSuggestions.clearResults();
                }
            }
        },
        
        
    makeSuggestionCall : function (valueurl){
            var 
    regExpValue = new RegExp(("^" value "$"), "i");
            var 
    exists false;
            var 
    suggestionItem;
            var 
    url url + ((/\?/.test(url))? "&" "?") + this.urlExt + ((this.addSearchTermToQueryString)? value "") + "&where=" this.searchOptWhere "&status=" this.searchOptStatus "&orderwhat=" this.searchOptOrderWhat "&orderby=" this.searchOptOrderBy "&rank=" this.searchOptRank.join(',');
            for(var 
    i=0i<this.suggestions.lengthi++){
                
    suggestionItem this.suggestions[i];
                if(
    regExpValue.test(suggestionItem[0]) && url == suggestionItem[2]){
                    
    exists true;
                    
    this.resultIndex i;
                    
    this.presentResult(this.suggestions[i][1]);
                    break;
                }
            };
            if(!
    exists){
                
    this.xmlHttp.onreadystatechange = function (){};
                
    this.xmlHttp.abort();
                
    this.currentValue value;
                
    this.currentURL url;
                
    this.xmlHttp.open("GET"urltrue);
                
    this.xmlHttp.onreadystatechange this.getResults;
                
    this.xmlHttp.send(null);
            }
        },
        
        
    getResults : function (){
            if(
    ajaxSuggestions.xmlHttp.readyState == && ajaxSuggestions.xmlHttp.responseText.length 0){
                
    ajaxSuggestions.loadResults();
            }
        },
        
        
    loadResults : function (){
            
    this.resultIndex this.suggestions.length;
            
    this.suggestions.push([this.currentValuethis.xmlHttp.responseTextthis.currentURL]);
            
    this.presentResult();
        },
        
        
    presentResult : function (){
            
    this.elmToPresentResultsIn.innerHTML this.suggestions[this.resultIndex][1];
            var 
    coordinates this.getCoordinates();
            var 
    elm this.elmResultsContainer.style;
            
    elm.left coordinates[0] + this.offsetLeft "px";
            
    elm.top coordinates[1] + this.currentElm.offsetHeight this.offsetTop "px";
            if(
    this.sameWidthAsInputElm){
                
    elm.width this.currentElm.offsetWidth "px";
            }
            
    this.applyResultEvents();
            
    elm.display "block";
            
    this.resultsAreVisible true;
            if(
    this.addKeyNavigationEvents && /38|40/.test(this.currentKeyEvent)){
                if(!
    this.valueAddedFromResultsListToInput){
                    
    this.selectedItem = -1;
                }
                
    this.navigateResults(nullthis.currentKeyEvent);
            }
        },
        
        
    clearResults : function (justClear){
            if(
    this.elmResultsContainer && this.elmToPresentResultsIn){
                if(!
    justClear){
                    
    this.elmResultsContainer.style.display "none";
                    
    this.resultsAreVisible false;
                }
                
    this.elmToPresentResultsIn.innerHTML "";
                
    this.selectedItem = -1;
            }
        },
        
        
    clearResultsElement : function (){
            
    ajaxSuggestions.clearResults();
        },
        
        
    navigateResults : function (evtkeyCode){
            if(
    ajaxSuggestions.currentElm && ajaxSuggestions.elmToPresentResultsIn){
                var 
    event = (typeof evt != "undefined")? evt event;
                if(
    typeof ajaxSuggestions.elmToPresentResultsIn.getElementsByClassName != "function"){
                    
    ajaxSuggestions.elmToPresentResultsIn.getElementsByClassName ajaxSuggestions.elmByClass;
                }
                var 
    results ajaxSuggestions.elmToPresentResultsIn.getElementsByClassName(ajaxSuggestions.itemClassName);
                var 
    selectedItem = (!evt && keyCode == 38)? results.length ajaxSuggestions.selectedItem;
                var 
    keyCode keyCode || event.keyCode;
                var 
    navigateUp keyCode == 37 || keyCode == 38;
                var 
    navigateDown keyCode == 39 || keyCode == 40;
                if(
    results.length && (navigateUp || navigateDown)){
                    if(
    navigateUp){
                        if((
    selectedItem 1) >= 0){
                            
    selectedItem--;
                        }
                        else{
                            
    selectedItem = -1;
                        }
                    }        
                    else if(
    navigateDown){
                        if((
    selectedItem 1) < results.length){
                            
    selectedItem++;
                        }
                        else{
                            
    selectedItem = -1;                
                        }
                    }
                    var 
    item;
                    var 
    classToRemove;
                    for(var 
    i=0i<results.lengthi++){
                        
    item results[i];
                        
    classToRemove = new RegExp((ajaxSuggestions.itemSelectedClassName "\s?"), "i");
                        
    item.className item.className.replace(classToRemove"").replace(/^\s?|\s?$/g"");
                    };
                    
    ajaxSuggestions.selectedItem selectedItem;
                    var 
    elmToFocus ajaxSuggestions.currentElm;
                    if(
    selectedItem > -1){
                        var 
    currentItem results[selectedItem];
                        var 
    currentClass item.className;
                        if(!new 
    RegExp(ajaxSuggestions.itemSelectedClassName"i").test(currentClass)){
                            
    currentItem.className currentClass + ((currentClass.length 0)? " " "") + ajaxSuggestions.itemSelectedClassName;
                        }
                        
    elmToFocus results[selectedItem];
                    }
                    try{
                        
    elmToFocus.focus();
                    }
                    catch(
    e){
                        
    // Just in case... :-)
                    
    }
                    if(
    event){
                        if(
    event.preventDefault){
                            
    event.preventDefault();
                        }
                        else{
                            
    event.returnValue false;
                        }
                        if(
    event.stopPropagation){
                            
    event.stopPropagation();
                        }
                        else{
                            
    event.cancelBubble true;
                        }
                    }
                    return 
    false;
                }
                else if(
    keyCode == 27){
                    
    ajaxSuggestions.clearResults();
                    try{
                        
    ajaxSuggestions.currentElm.focus();
                    }
                    catch(
    e){
                        
    // Just in case... :-)
                    
    }
                }
            }
        },
        
        
    applyResultEvents : function (){
            if(
    typeof this.elmToPresentResultsIn.getElementsByClassName != "function"){
                
    this.elmToPresentResultsIn.getElementsByClassName this.elmByClass;
            }
            var 
    insertValueItems this.elmToPresentResultsIn.getElementsByClassName(this.itemInsertValueIntoInputClassName"a");
            var 
    item;
            for(var 
    i=0i<insertValueItems.lengthi++){
                
    item insertValueItems[i];
                
    item.inputRef this.currentElm;
                
    this.addEvent(item"click"this.insertValueIntoField);
            };        
        },
        
        
    insertValueIntoField : function (evt){
            var 
    elm = (/a/i.test(this.nodeName))? this evt.srcElement;
            var 
    input elm.inputRef;
            var 
    value elm.getAttribute("href");
            if(!new 
    RegExp(value).test(input.value)){
                
    input.value = ((input.value.length && /;/i.test(input.value))? (input.value value) : value) + ajaxSuggestions.itemSeparator;
            }
            if(
    evt.preventDefault){
                
    evt.preventDefault();
            }
            else{
                
    evt.returnValue false;
            }
            if(
    evt.stopPropagation){
                
    evt.stopPropagation();
            }
            else{
                
    evt.cancelBubble true;
            }
            if(
    ajaxSuggestions.itemInsertValueSetFocusToInput){
                try{
                    
    input.focus();
                }
                catch(
    e){
                    
    // Just in case... :-)
                
    }
            }
            if(
    ajaxSuggestions.hideResultsWhenInsertValueIsSelected){
                
    ajaxSuggestions.clearResults();
            }
            
    ajaxSuggestions.valueAddedFromResultsListToInput true;
        },
        
        
    preventInputClickBubbling : function (evt){
            if(
    evt.preventDefault){
                
    evt.preventDefault();
            }
            else{
                
    evt.returnValue false;
            }
            if(
    evt.stopPropagation){
                
    evt.stopPropagation();
            }
            else{
                
    evt.cancelBubble true;
            }
            return 
    false;
        },
        
        
    preventDefaultForArrowKeys : function (evt){
            var 
    keyCode evt.keyCode;
            var 
    navigateUp keyCode == 37 || keyCode == 38;
            var 
    navigateDown keyCode == 39 || keyCode == 40;
            if((!
    evt.ctrlKey && !evt.metaKey) && ajaxSuggestions.resultsAreVisible && (navigateUp || navigateDown)){
                if(
    evt.preventDefault){
                    
    evt.preventDefault();
                }
                else{
                    
    evt.returnValue false;
                }
                if(
    evt.stopPropagation){
                    
    evt.stopPropagation();
                }
                else{
                    
    evt.cancelBubble true;
                }
                return 
    false;
            }    
        },
        
        
    getCoordinates : function (){
            var 
    elm this.currentElm;
            var 
    offsetLeft 0;
            var 
    offsetTop 0;
            while(
    elm.offsetParent){
                
    offsetLeft += elm.offsetLeft;
                
    offsetTop += elm.offsetTop;
                if(
    elm.scrollTop 0){
                    
    offsetTop -= elm.scrollTop;
                }
                
    elm elm.offsetParent;
            }
            return [
    offsetLeftoffsetTop];
        },
        
        
    closeSession : function (){
            
    delete ajaxSuggestions;
            
    ajaxSuggestions null;
        },
        
        
    elmByClass : function (classNametag){
            return 
    ajaxSuggestions.getElementsByClassName.call(thisclassNametag);
        },
        
        
    getElementsByClassName : function (classNametag){        
            var 
    elms = ((!tag || tag == "*") && this.all)? this.all this.getElementsByTagName(tag || "*");
            var 
    returnElms = [];
            var 
    className className.replace(/\-/g"\\-");
            var 
    regExp = new RegExp("(^|\\s)" className "(\\s|$)");
            var 
    elm;
            for(var 
    i=0i<elms.lengthi++){
                
    elm elms[i];        
                if(
    regExp.test(elm.className)){
                    
    returnElms.push(elm);
                }
            }
            return (
    returnElms);
        },

        
    addEvent : function (elmevtfunc){
            if(
    elm){
                if(
    elm.addEventListener){
                    
    elm.addEventListener(evtfuncfalse);
                }
                else if(
    window.attachEvent){
                    
    elm.attachEvent(("on" evt), func)
                }
            }
        }
    };
    // ---
    ajaxSuggestions.addEvent(window"load", function(){ajaxSuggestions.init();});
    ajaxSuggestions.addEvent(window"unload", function(){ajaxSuggestions.closeSession();});
    // --- 
    Last edited by -Adam; 04-08-2010 at 07:27 PM.

Posting Permissions

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