www.webdeveloper.com
Results 1 to 3 of 3

Thread: ajax problem

Hybrid View

  1. #1
    Join Date
    Aug 2013
    Posts
    8

    ajax problem

    my friends i have ajax proplem the code not working
    how can i get id from part_a_new.php

    database

    bring data from substation table
    id , station, make , last

    to put troubleshoot table

    id , refno , station , make , last , engname , username

    i need when select station from form automaticly make and last show from substation table

    the code

    HTML Code:
     mysql_select_db($database_trsh, $trsh);
    $query_substation = "SELECT * FROM substations";
    $substation = mysql_query($query_substation, $trsh) or die(mysql_error());
    $row_substation = mysql_fetch_assoc($substation);
    $totalRows_substation = mysql_num_rows($substation);
    
    <head>
    <script type="text/javascript" language="javascript" src="css/jquery2.js"></script>
    <script language="javascript" type="text/javascript">
    
    function getXMLHTTP() { //fuction to return the xml http object
    		var xmlhttp=false;	
    		try{
    			xmlhttp=new XMLHttpRequest();
    		}
    		catch(e)	{		
    			try{			
    				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
    			}
    			catch(e){
    				try{
    				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    				}
    				catch(e1){
    					xmlhttp=false;
    				}
    			}
    		}
    		 	
    		return xmlhttp;
        }
    	
    	function getMake(id) {		
    		
    		var strURL="part_a_new.php?id="+id;
    		var req = getXMLHTTP();
    		
    		if (req) {
    			
    			req.onreadymakechange = function() {
    				if (req.readyMake == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('makediv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("POST", strURL, true);
    			req.send(null);
    		}		
    	}
    	function getMake(id) {		
    		var strURL="part_a_new.php?id="+id;
    		var req = getXMLHTTP();
    		
    		if (req) {
    			
    			req.onreadymakechange = function() {
    				if (req.readyState == 4) {
    					// only if "OK"
    					if (req.status == 200) {						
    						document.getElementById('lastdiv').innerHTML=req.responseText;						
    					} else {
    						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
    					}
    				}				
    			}			
    			req.open("POST", strURL, true);
    			req.send(null);
    		}
    				
    	}
    </script>
    </head>
    
    <body>
    <?php
    //this code from findmake.php
    ?>
    
    
    <?php $make=intval($_POST['id']);
    $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('trsh');
    $query="SELECT id,make FROM substations WHERE id ='$make'";
    $result=mysql_query($query);
    
    ?>
    
    
    <?php 
    //end of findmake.php
    ?>
    
    <?php 
    //this code from findlast.php
    ?>
    <?php $last=intval($_POST['id']);
    $link = mysql_connect('localhost', 'root', ''); //changet the configuration in required
    if (!$link) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db('trsh');
    $query="SELECT id,last FROM substations WHERE id ='$last'";
    $result=mysql_query($query);
    
    ?>
    
    <?php
    //end of findlast.php
    ?>
    <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
      <table align="center">
     <tr valign="baseline">
          <td nowrap="nowrap" align="right">Ref_no:</td>
          <td><input type="text" name="ref_no" value="" size="32" /></td>
        </tr>
    
    <tr valign="baseline">
          <td nowrap="nowrap" align="right">Station:</td>
          <td><select name="substation_name" onChange="getmake(this.value)">
            <?php
    do {  
    ?>
            <option value="<?php echo $row_substation['id']?>"><?php echo $row_substation['station']?></option>
            <?php
    } while ($row_substation = mysql_fetch_assoc($substation));
      $rows = mysql_num_rows($substation);
      if($rows > 0) {
          mysql_data_seek($substation, 0);
    	  $row_substation = mysql_fetch_assoc($substation);
      }
    ?>
          </select></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Make:</td>
          <td><div id="makediv">
          <select name="make" onchange="getMake(<?php echo $make ?>,this.value)">
      <option></option>
      <?php while($row=mysql_fetch_array($result)) { ?>
      <option value><?php echo $row['make']?></option>
      <?php } ?>
    </select>
          </div></td>
        </tr>
        <tr> </tr>
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Last:</td>
      <td><div id="lastdiv">
      
      <select name="last" onchange="getMake(<?php echo $last ?>,this.value)">
      <option></option>
      <?php while($row=mysql_fetch_array($result)) { ?>
      <option value><?php echo $row['last']?></option>
      <?php } ?>
    </select>
          
          </div></td>
        </tr>
      </table>
    </body>
    </html>
    <?php
    mysql_free_result($substation);
    ?>
    can any body tell me where is my mistake??

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by veto611 View Post
    Code:
        function getMake(id) {        
            
            var strURL="part_a_new.php?id="+id;
            var req = getXMLHTTP();
            
            if (req) {
                
                req.onreadymakechange = function() {
    
                req.onReadyStateChange //should be
    
                    if (req.readyMake == 4) {
                          
                         req.readyState // should be
     
                        // only if "OK"
                        if (req.status == 200) {                        
                            document.getElementById('makediv').innerHTML=req.responseText;                        
                        } else {
                            alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                        }
                    }                
                }            
                req.open("POST", strURL, true);
                req.send(null);
            }        
        }
        function getMake(id) {        duplicate function overwrites above
            var strURL="part_a_new.php?id="+id;
            var req = getXMLHTTP();
            
            if (req) {
                
                req.onreadymakechange = function() {
                    if (req.readyState == 4) {
                        // only if "OK"
                        if (req.status == 200) {                        
                            document.getElementById('lastdiv').innerHTML=req.responseText;                        
                        } else {
                            alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                        }
                    }                
                }            
                req.open("POST", strURL, true);
                req.send(null);
            }
                    
        }
    There may be other problems.

  3. #3
    Join Date
    Aug 2013
    Posts
    8
    iam fix proplem with this code

    <option value="<?php echo $row_station['id']?>"> <?php echo $row_station['station']?> </option>

    <script> $("#selectstation").change(function (){
    var VALUESTATION = $("#selectstation").val();
    $("#makediv").load("findmake.php?id="+VALUESTATION);
    $("#lastdiv").load("findlast.php?id="+VALUESTATION);
    //alert(VALUESTATION);
    });
    </script>

    but how can i get label not value ineed to get name not id can any one help me??

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles