Announcement

Collapse
No announcement yet.

Listbox via Ajax

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

  • Listbox via Ajax

    Fetch data for listboxes through Ajax. As a reminder...


    The script

    HTML Code:
    <script language="JavaScript">
    <!--
    /******************************************************************************/
    /*                          The AJAX Listbox, by TMM <thorne@tornevall.net>   */
    /* Yes. You need the AJAX-routines to fetch the data. That's not included here*/
    /******************************************************************************/
    function ajaxlist()
    {
        var ajquery = "";                                    // Define the query string
        var selObj = arguments[0];                            // Fetch input from this object
        var goUrl = arguments[1];                            // Fetch output from this site
        var destination = arguments[2];                     // Put output into this object
        for (var i = 0; i < selObj.options.length; i++)        // Loop through a listbox, find all selected items
        {
            if (selObj.options[i].selected)
            {
                ajquery = ajquery + "&" + selObj.name + "=" + selObj.options[i].value;        // Add all selected items to a query string
            }
        }
    
        // Fix the url and the query string, and fix the trailing slash in case of user failure (:P)
        var newquery = goUrl.replace(/[/]$/, '') + "/" + ajquery.replace(/^&/gi, '?');
    
        // Find the destination object...
        var destinationobject = document.getElementById(destination);
        
        // ... and return our request into that place ...
        destinationobject.innerHTML = AJAX(newquery);
    }
    -->
    </script>


    The html

    HTML Code:
    <form name="testajaxclickbox" method="post" action="">
      <select name="ajclick" size="6" multiple id="ajclick" onchange="ajaxlist(this, '/ajax_run.php', 'mydestination')">
        <option value="1">Test 1</option>
        <option value="2">Test 2</option>
        <option value="3">Test 3</option>
      </select>
    </form>
    
    <div name="mydestination" id="mydestination">Select items in the list above, to 
      show them here...</div>
    -
Sorry, you are not authorized to view this page
Working...
X