0

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);                   

            ?>
4
Contributors
5
Replies
28
Views
3 Years
Discussion Span
Last Post by accra
1

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

1

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);

Edited by JorgeM

0

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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.