page refresh problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • desaimadhavi
    New Member
    • Nov 2006
    • 4

    page refresh problem

    hi, everybody
    I am new at ajax.
    U31 ระบบฝาก-ถอน อัตโนมัติที่เร็วที่สุดในไทย มั่นใจได้ในความปลอดภัย 100% เข้าเล่นได้ทันทีไม่ต้องรอนาน บริการตลอด 24 ชั่วโมง คลิกเลย!


    From this url i got a example of this chained selected box.But in this getcities.php thre is static value.I want it from database in which i have made 1 table in mysql of city.there are 3 fields in that. one is id,2nd is cityname and 3 is country name. city is base on country name but there is error come

    in html syntax error on line 69.
  • vssp
    Contributor
    • Jul 2006
    • 268

    #2
    Code:
    <script language="javascript">
    <!--
    //-------------------------------------------
    
    function checkSearchCriteria1()
    {
    	
    		if(window.XMLHttpRequest)
    		{
    			http=new XMLHttpRequest();
    		}
    		else if(window.ActiveXObject)
    		{
    			http=new ActiveXObject("Microsoft.XMLHTTP");
    		}
    		//var url = "countrylist1.php?rid="+document.getElementById("Country").value;
    		var url = "citylist.php?rid="+document.getElementById("country").value;
    		//alert(url);  
    		//mlsaddress=address;
    		http.open("GET", url , true);
    		
    		http.onreadystatechange = countryprocess1;
    		
    		http.send(null);
    }
    
    function countryprocess1()
    {
    
    	if (http.readyState == 4) {
    //alert (http.readyState);
        // Split the comma delimited response into an array
    		if(http.status==200)
            {  
    
    //alert (http.status);            
    //alert (http.responseText);
    //alert (document.getElementById("school").value);
    						document.getElementById("city").disabled=false;
                            document.getElementById("city").length=0;
                            document.getElementById("city").options[0]=new Option("Select City"," ");
    
    		if(http.responseText!="No values")
                            {
    			
    				var clist=http.responseText.split("_");
    	                        for(i=0;i<clist.length;i++)
                                    {
                                            var myclist=clist[i].split(",");
                                          // alert (myclist[0]);
    					document.getElementById("city").options[i+1]=new Option(myclist[1],myclist[1]);
    				}
    			}	
    		else
    		{
    			document.getElementById("city").length=0;
    			document.getElementById("city").options[0]=new Option("Select City"," ");
    		}						
    		}
       
      }
    }
    </script>
    try thsi code

    Comment

    • desaimadhavi
      New Member
      • Nov 2006
      • 4

      #3
      Thankyou, For Reply
      But for this code is notworkable by me.Have yo seen that link which i have put.
      For adding ur script ?I have to include that ajax.js or not
      and in php I have put below code in no case

      [CODE=php]$q = "select cityname from city where countryname='no '";
      $result = mysql_query($q) or die("Error in Query" . mysql_error());
      while($row = mysql_fetch_arr ay($result, MYSQL_ASSOC))
      {
      //$i=1;
      $city = $row['cityname'];
      echo "obj.option s[obj.options.len gth] = new Option($city,1) ;\n";

      //$i = $i + 1;
      }
      [/CODE]
      For Your information.
      Thank You.


      Originally posted by vssp
      Code:
      <script language="javascript">
      <!--
      //-------------------------------------------
      
      function checkSearchCriteria1()
      {
      	
      		if(window.XMLHttpRequest)
      		{
      			http=new XMLHttpRequest();
      		}
      		else if(window.ActiveXObject)
      		{
      			http=new ActiveXObject("Microsoft.XMLHTTP");
      		}
      		//var url = "countrylist1.php?rid="+document.getElementById("Country").value;
      		var url = "citylist.php?rid="+document.getElementById("country").value;
      		//alert(url);  
      		//mlsaddress=address;
      		http.open("GET", url , true);
      		
      		http.onreadystatechange = countryprocess1;
      		
      		http.send(null);
      }
      
      function countryprocess1()
      {
      
      	if (http.readyState == 4) {
      //alert (http.readyState);
          // Split the comma delimited response into an array
      		if(http.status==200)
              {  
      
      //alert (http.status);            
      //alert (http.responseText);
      //alert (document.getElementById("school").value);
      						document.getElementById("city").disabled=false;
                              document.getElementById("city").length=0;
                              document.getElementById("city").options[0]=new Option("Select City"," ");
      
      		if(http.responseText!="No values")
                              {
      			
      				var clist=http.responseText.split("_");
      	                        for(i=0;i<clist.length;i++)
                                      {
                                              var myclist=clist[i].split(",");
                                            // alert (myclist[0]);
      					document.getElementById("city").options[i+1]=new Option(myclist[1],myclist[1]);
      				}
      			}	
      		else
      		{
      			document.getElementById("city").length=0;
      			document.getElementById("city").options[0]=new Option("Select City"," ");
      		}						
      		}
         
        }
      }
      </script>
      try thsi code
      Last edited by gits; Dec 2 '07, 01:29 PM. Reason: added code tags

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Then why don't you change the getcities.php script so that it reads the MySQL data instead of pulling its result from a static array? Can't that difficult to do that.

        Ronald :cool:

        Comment

        • satpal singh
          New Member
          • Dec 2007
          • 1

          #5
          Originally posted by desaimadhavi
          hi, everybody
          I am new at ajax.
          U31 ระบบฝาก-ถอน อัตโนมัติที่เร็วที่สุดในไทย มั่นใจได้ในความปลอดภัย 100% เข้าเล่นได้ทันทีไม่ต้องรอนาน บริการตลอด 24 ชั่วโมง คลิกเลย!


          From this url i got a example of this chained selected box.But in this getcities.php thre is static value.I want it from database in which i have made 1 table in mysql of city.there are 3 fields in that. one is id,2nd is cityname and 3 is country name. city is base on country name but there is error come

          in html syntax error on line 69.
          hi its my second day on ajax
          i m trying to help u
          plz dont mind if it will not work n reply me with the errors
          i m giving code in jsp convert it in php whatever u like
          in ur url page id "getciti.ph p" write this code whitch in jsp convert it

          [CODE=java]<%
          Vector val=(Vector)MyC lass.getRecord( );
          String record="";
          for(int i=0;i<val.size( );i++){ response.getWri ter().write(rec ord.concat((Str ing)val.element At(i)).concat(" ,"));
          }
          %>[/CODE]
          this method set records in xmlHttp.respons eText Object with ', ' comma seperator

          put this code in ur function where u r want to get records
          [CODE=javascript]results = xmlHttp.respons eText.split("," );
          document.getEle mentById('ID'). value = results[0];
          document.getEle mentById('cityn ame').value = results[1];
          document.getEle mentById('count ry').value = results[2];
          [/CODE]
          i think it will help u
          from
          satpal singh
          Last edited by gits; Dec 2 '07, 12:14 PM. Reason: added code tags

          Comment

          Working...