SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Help tweaking a js function to constructs a URL

    I am trying to get a page to update a selection of php mysql results via ajax.
    I can get this to work with only 1 dropdown list but I have a maximum of 14 inputs the user can choose from to filter the results. I am using the following script on the page to call the .php page which runs the updated query on the table and returns the filtered results.

    The javascript I have on the page which is called using onchange on one of the dropdowns is:

    Code:
    <script type="text/javascript">
    function showCars(str)
    {
    if (str=="")
      {
      document.getElementById("txtHint").innerHTML="";
      return;
      }
    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.onreadystatechange=function()
      {
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","getcars.php?q="+str,true);
    xmlhttp.send();
    }
    </script>


    I need to get a selection of form inputs to generate a url similar in style to the one shown below:

    getCars.php?Make=Claret&Model=2005&Tophats=Funny


    Can anyone show me how I can achieve this please? I think if I can bget this bit to work I will be able to sort out the other issues I have with the site I'm working on.

    Any help would be extremely appreciated, thanks in advance!

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    381
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is anyone able to show me how to construct the url in the way I need to by changing the code I've posted? Have I not given enough information? I'm realy struggling with this, please help.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,707
    Mentioned
    102 Post(s)
    Tagged
    4 Thread(s)
    Which method are you using to set up the onchange event of the select box? If you are using the traditional model where scripting assigns a function to the onchange property of the element, that will be easier to help with.

    If instead you are using inline event attributes, that will serve to hinder any progress that may be made.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •