MySql problems

driveflexfuel

New Member
Messages
159
Reaction score
0
Points
0
I have been trying to get this code working and I have hit a stand still. I do not know if it is by my error or the way I am coding the js. Currently it loads correctly half the time and the other half the form shows blank and the load time of each box is slow. If I refresh the page it does not refresh the form data. If there is a better way of coding this other then ajax I am willing to hand out 800 credits for the coding. Any language that works on x10 hosting I am in a crunch to get this finished and it is driveing me nuts.

Here is a line from the database.
year make model engine link to products
"1990","Acura","Integra","4 Cylinder","http://site.com/store"


Current Form
Code:
<form action="conversion_kits.php" method="post" id="myform" onSubmit="return send_query()">
<table border="1">
<tr><td>Year</td> <td><select  id="year" name="year" onChange="setdata('setyear','make')" >
<option id="year1">-Select Year-</option>

</select> </td></tr>
<tr><td>Make</td> <td><select id="make"  name="make" onChange="setdata('setmake','model')">
<option id ="make1">-Select Make-</option>
</select> </td></tr>


<tr><td>Model</td> <td>
<select id="model" name="model" onChange="setdata('setmodel','engine')">
<option id="model1">-Select Model-</option>
</select>
</td></tr>

<tr><td>Engine</td> <td>
<select id="engine" name="engine">
<option id="engine1">-Select Model-</option>
</select>
</td></tr>
</table>
<input type= "submit" name = "go" value="SendQuery">
</form>
Current javascript file
Code:
var request = false;

try {

  request = new XMLHttpRequest();

} catch (trymicrosoft) {

  try {

    request = new ActiveXObject("Msxml2.XMLHTTP");

  } catch (othermicrosoft) {

    try {

      request = new ActiveXObject("Microsoft.XMLHTTP");

    } catch (failed) {

      request = false;

    }

  }

}





if (!request)

  alert("Error initializing XMLHttpRequest!");



var url = 'kits.php';

var set_year =0;

var sid=null;//dont delete or edit

var selectids = new Array("year","make","model","engine");

function setdata(option,id) 

{

   resetchoose(id);

   sid = id; 

   //alert(sid);

   

   data=getdata(id);

   var t=new Date();

   var url = "product.php?option="+option+"&time="+t.getTime();

   request.open("POST",url, true);

   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   request.send(data);

   request.onreadystatechange = updateList;

   

}

function setyear(option,id) 

{

   resetchoose(id);

   sid = id; 

   //alert(sid);

   //data=getdata(id);

   var t=new Date();

   var url = "product.php?option="+option+"&time="+t.getTime();

   request.open("GET",url, true);

   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   request.send(null);

   request.onreadystatechange = updateList;

}

setyear('allyear','year');



function send_query()

{

   limit = selectids.length;

   //alert(limit);

   for(var i=0 ; i<limit; i++){

      si = document.getElementById(selectids[i]).selectedIndex;

      if (si==0){

         alert(selectids[i]+' is not selected');

         return false;

      }

   }

}

function getdata(curr)

{

   var data = null;

   var index =0;

   var cs = selectids[index];

   val = document.getElementById(cs).value;

   data = cs + "=" + encodeURIComponent(val);

   if (cs==curr) return data;

   index = index+1;

   while(curr!=selectids[index]){

      

      cs = selectids[index];

      val = document.getElementById(cs).value;

      data = data+"&"+cs + "=" + encodeURIComponent(val);

      index = index+1;

   }     

   return data;

}

function resetchoose(id)

{

   curr = id; 

   limit = selectids.length;

   //alert(limit);

   for(var i=0 ; i<limit; i++){

      if(curr==selectids[i]) {

         var index =i; 

         break;

         //alert(index)

      }

   }

   for(i=index;i<limit;i++){

      rs = selectids[i]

      //alert(rs+  'must reset');

      mr = document.getElementById(rs);

      if (mr!=null)document.getElementById(rs).selectedIndex=0;

   }

}



function updateList() {



   if (request.readyState == 4) {

       if (request.status == 200) {

        var make=request.responseText.split("|");

         //alert(make);

         var limit = make.length-1;
         //alert(limit);
         var list =document.getElementById(sid);

         var oid = sid+"1"; 

         var member = document.getElementById(oid);
         var nvg = document.getElementById(oid);
         member = nvg.nextSibling;

           

            while((member!= null))

           {
               
               list.removeChild(member);

               member=nvg.nextSibling;

           }

         

         for(var i=0; i<limit; i++){

            value = make[i];

            //alert(value);

            var newitem=document.createElement("option");

            newitem.setAttribute("value", value);

            var text = document.createTextNode(value);

            newitem.appendChild(text);

             list.appendChild(newitem);

       } 

       } else if (request.status == 404) {

         alert("URL does not exist.");

       } else {

         //alert("Status is: " + request.status);

       }

     }      

}

//resetchoose(-1);
Edit:
I found the error you can close the thread this is the new code.


Code:
var request = false;

try {

  request = new XMLHttpRequest();

} catch (trymicrosoft) {

  try {

    request = new ActiveXObject("Msxml2.XMLHTTP");

  } catch (othermicrosoft) {

    try {

      request = new ActiveXObject("Microsoft.XMLHTTP");

    } catch (failed) {

      request = false;

    }

  }

}





if (!request)

  alert("Error initializing XMLHttpRequest!");



var url = 'deneme2.php';

var set_year =0;

var sid=null;//dont delete or edit

var selectids = new Array("year","make","model","engine");

function setdata(option,id) 

{

   resetchoose(id);

   sid = id; 

   //alert(sid);

   //alert("test");

   data=getdata(id);

   var t=new Date();

   var url = "db.php?option="+option+"&time="+t.getTime();

   request.open("POST",url, true);

   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   request.send(data);

   request.onreadystatechange = updateList;

   

}

function setyear(option,id) 

{
   resetchoose(id);

   sid = id; 

   //alert(sid);

   //data=getdata(id);

   var t=new Date();

   var url = "db.php?option="+option+"&time="+t.getTime();

   request.open("GET",url, true);

   request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

   request.send(null);

   request.onreadystatechange = updateList;

}

setyear('allyear','year');



function send_query()

{

   limit = selectids.length;

   //alert(limit);

   for(var i=0 ; i<limit; i++){

      si = document.getElementById(selectids[i]).selectedIndex;

      if (si==0){

         alert(selectids[i]+' is not selected');

         return false;

      }

   }

}

function getdata(curr)

{

   var data = null;

   var index =0;

   var cs = selectids[index];

   val = document.getElementById(cs).value;

   data = cs + "=" + encodeURIComponent(val);

   if (cs==curr) return data;

   index = index+1;

   while(curr!=selectids[index]){

      

      cs = selectids[index];

      val = document.getElementById(cs).value;

      data = data+"&"+cs + "=" + encodeURIComponent(val);

      index = index+1;

   }     

   return data;

}

function resetchoose(id)

{

   curr = id; 

   limit = selectids.length;

   //alert(limit);

   for(var i=0 ; i<limit; i++){

      if(curr==selectids[i]) {

         var index =i; 

         break;

         //alert(index)

      }

   }

   for(i=index;i<limit;i++){

      rs = selectids[i]

      //alert(rs+  'must reset');

      mr = document.getElementById(rs);

      if (mr!=null)document.getElementById(rs).selectedIndex=0;

   }

}



function updateList() {



   if (request.readyState == 4) {

       if (request.status == 200) {
//alert(request.responseText);
        var make=request.responseText.split("|");

         //alert(make);

         var limit = make.length-1;
         //alert(limit);
         var list =document.getElementById(sid);

         var oid = sid+"1"; 
          //alert(oid);
         var member = document.getElementById(oid);
         var nvg = document.getElementById(oid);
         member = nvg.nextSibling;
            while((member!=null))
           {
               list.removeChild(member);
               member=nvg.nextSibling;
           }

         

         for(var i=0; i<limit; i++){

            value = make[i];

            //alert(value);

            var newitem=document.createElement("option");

            newitem.setAttribute("value", value);

            var text = document.createTextNode(value);

            newitem.appendChild(text);

             list.appendChild(newitem);

       } 

       } else if (request.status == 404) {

         alert("URL does not exist.");

       } else {

         //alert("Status is: " + request.status);

       }

     }      

}

//resetchoose(-1);
 
Last edited:
Top