I am absolutely newbie to Ajax and I need to have this fixed by tomorrow as I have a project to complete so anyone who could help me, I would be really greatful!

This is what I have cooked up so far
index.php

<html> 
<body> 

<script language="javascript" type="text/javascript"> 
<!--  
//Browser Support Code 
function ajaxFunction(){ 
    var ajaxRequest;  // The variable that makes Ajax possible! 
     
    try{ 
        // Opera 8.0+, Firefox, Safari 
        ajaxRequest = new XMLHttpRequest(); 
    } catch (e){ 
        // Internet Explorer Browsers 
        try{ 
            ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); 
        } catch (e) { 
            try{ 
                ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); 
            } catch (e){ 
                // Something went wrong 
                alert("Your browser broke!"); 
                return false; 
            } 
        } 
    } 
    // Create a function that will receive data sent from the server 
    ajaxRequest.onreadystatechange = function(){ 
        if(ajaxRequest.readyState == 4){ 
            var ajaxDisplay = document.getElementById('ajaxDiv'); 
            ajaxDisplay.innerHTML = ajaxRequest.responseText; 
        } 
    } 
    var deviceid = document.getElementById('deviceid').value; 
    var queryString = "?deviceid=" + deviceid; 
    ajaxRequest.open("GET", "data.php" + queryString, true); 
    ajaxRequest.send(null);  
} 

//--> 
</script> 

<form name='myForm' method="post" action="test.php"> 
Device ID: <input type='text' id='deviceid' /> <br /> 
<input type='button' onclick='ajaxFunction()' value='Query MySQL' /> 
<div id='ajaxDiv'> 
</div> 
<input name="Submit" type="submit" value="submit" /> 

</form> 
</body> 
</html>

data.php

<?php 
$dbhost = "localhost"; 
$dbuser = "root"; 
$dbpass = ""; 
$dbname = "ajax"; 

//Connect to MySQL Server 
mysql_connect($dbhost, $dbuser, $dbpass); 

//Select Database 
mysql_select_db($dbname) or die(mysql_error()); 
// Retrieve data from Query String 
$deviceid = $_GET['deviceid']; 

// Escape User Input to help prevent SQL Injection 
$deviceid = mysql_real_escape_string($deviceid); 
    //build query 
$query = "SELECT * FROM pmc_devicedata_100902 WHERE DeviceID = '$deviceid'"; 
$qry_result = mysql_query($query) or die(mysql_error()); 

//Build Result String 

// Insert a new row in the table for each person returned 
while($row = mysql_fetch_array($qry_result)){ 
$aux = $row['AuxBarcode']; 
} 

$display_string .= "Aux:<input type='text' name='aux' value='$aux' disabled />"; 

echo $display_string; 
?>

test.php

<?php 
$aux = $_POST['aux']; 
echo "AUX: $aux"; 
?>

test.php does not print any results. I think AJAX Is just displaying the results but not passing the value to the PHP script (test.php). This is a very basic script which I plan to improve it once I get this one to work. Any help provided would be appreciated

Recommended Answers

All 4 Replies

If you keep a field as "disabled" the browser will not submit/post the value to the server. You can change that to readonly instead and THEN it should submit the value of the text field.

If you keep a field as "disabled" the browser will not submit/post the value to the server. You can change that to readonly instead and THEN it should submit the value of the text field.

Brilliant! I literally banged my head all day yesterday to get this to work. Thank you for your timely help :)

Glad to help.

PS: Be sure to mark the thread as solved.

Done, thanks again!

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.