Hi all, I have this ajax script that accepts only one value at a time. I want to send more than one value to mysql for processing... but am not so good with javascript, pls point me in the right way....thanks

// auto select vehicle # and fleet #
        <script>
                function showFleet_Loc(str)
                {
                if (str=="")
                  {
                  document.getElementById("fleet_loc_Hint").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("fleet_loc_Hint").innerHTML=xmlhttp.responseText;
                    }
                  }
                xmlhttp.open("GET","fleet_loc_select.php?q="+str,true);
                xmlhttp.send();
                }
             </script>

Here is fleet_loc_select.php

                $q=$_GET["q"];

                $cd ="UPDATE vehicles SET image_file='$newimage' WHERE svreg='$q'"; 
                mysql_query($cd);                   

            ?>

Do you want to use jquery?
Do you like to provide functionality for users with javascript disabled?
Can you use pdo?

These are the question you should answer before going forward

And to help you with your question you can send as many inputs form a form via jquery ajax to the db and retrieve them to see how visit this link form the documentaion
http://api.jquery.com/jQuery.ajax/
Hope this helps

There are several options...if you are going to use plain JavaScript/AJAX, you can send multiple values using the query string approach if you are sending via GET, or you use POST as well. both have the ability to send mutliple values. If you use POST, you have to adjust your PHP code to retrieve POST parameters.

GET

xmlhttp.open("GET","fleet_loc_select.php?q1="+str1+"q2="+str2,true);
xmlhttp.send();

POST

xmlhttp.open("POST","fllet_loc_select.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("q1="+str1+"&q2="+str2);

As Dani said, you could try using jQuery also, it has all of these functionalities enable right out of the box.

thanks for your help, its just that am very comfortable with this script. it works fine with no problem, i will take your advice, thax...

thaxs Szabi Zsoldos

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.