www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 12-28-2006, 12:22 PM
    nookle nookle is offline
    Registered User
     
    Join Date: Dec 2006
    Posts: 1
    Autocomplete Text Field using Database Results

    I have script that suggests autocomplete terms as a user is typing text into a field. Currently, the script uses a hard-coded array as I wanted to get the function working first. Towards the end of the script, I define and call the array:

    function createAutoComplete(){
    var aNames = [
    "A MACEO WALKER MIDDLE SCHOOL",
    "ADAMSVILLE JUNIOR / SENIOR HIGH SCHOOL",
    "AIRWAYS MIDDLE",
    "ALCOA HIGH SCHOOL"
    ...
    ];

    new AutoComplete(
    aNames,
    document.getElementById('theText'),
    document.getElementById('theDiv'),
    25
    );
    }

    Additionally, I have a separate function that executes when the page loads to generate an array from a SQL query. The data is defined by in the array '$result' and contains the information:

    Array (
    [0] => Array ( [name] => A MACEO WALKER MIDDLE SCHOOL )
    [1] => Array ( [name] => ADAMSVILLE JUNIOR / SENIOR HIGH SCHOOL )
    [2] => Array ( [name] => AIRWAYS MIDDLE )
    [3] => Array ( [name] => ALCOA HIGH SCHOOL ))
    ...
    (The array actually has over 800 elements in the result.)

    Since the array contents will differ depending on a State ID, how do I pass the $result data into the javascript?

    Thanks.
    Reply With Quote
      #2  
    Old 12-28-2006, 12:29 PM
    so_is_this so_is_this is offline
    don't ask
     
    Join Date: Oct 2006
    Posts: 1,304
    This is actually a PHP question.
    Reply With Quote
      #3  
    Old 12-28-2006, 12:57 PM
    so_is_this so_is_this is offline
    don't ask
     
    Join Date: Oct 2006
    Posts: 1,304
    This is just an example of building a JavaScript array from PHP:
    PHP Code:
    <?php
    ?>

    <script type="text/javascript">
    <!--//
    var image_list = new Array(
    <?php
        
    while($row = mysql_fetch_assoc($result)):
            echo
    '"' . $row['image_filepath'] . '",' . "\n";
        endwhile;
    ?>
    'END');
    image_list.length -= 1;
    //-->
    </script>
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:32 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.