Jump to content

urgent help form submitting.


jayzz

Recommended Posts

hi guys, i am new to Ajax and I've hit a little snag with the code that i am writing. i have student information that is retrieved from a database and displayed in forms on a page i then have two checkbox's  where when they are checked the information is submitted into the database the problem that i am having is only the first form is being submitted. I am thinking that it is to do with the form name needing to to be submitted to Ajax, but I am not sure how to do that. could someone give me a sample of how this is done. i have been searching this for a few days but cant find anything and i would like to get this sorted so i can move on to the next part of the site.

 

thanks.

 

here is the code

<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 = "<img src='images/absent.gif' width='20' height='20'/>";
	}
}
var stu_id = document.getElementById('stu_id').value;
var class_id = document.getElementById('class_id').value;
var absent = document.getElementById('absent').value;
var uniform = document.getElementById('uniform').value;
var queryString = "?stu_id=" + stu_id + "&class_id=" + class_id + "&absent=" + absent + "&uniform=" + uniform;
ajaxRequest.open("GET", "insert_data.php" + queryString, true);
ajaxRequest.send(null); 
}


</script>

<?php
echo'<link rel="stylesheet" type="text/css" href="body.css">';
$class_id=$_POST['class_id'];

include 'sql_config.php';

$student_id = $rc->Fields("StudentID");
$first_name = $rc->Fields("FirstName");
$last_name = $rc->Fields("LastName");
$yr_level = $rc->Fields("YearLevel");



echo '<table>';

$counter = 0;
$cells_per_row = 7;
$tables = 0;

while (!$rc->EOF) {

$student = $student_id->value;	
$fname = $first_name->value;
$lname = $last_name->value;

$counter++;
if(($counter % $cells_per_row) == 1) { echo '<tr>'; }
echo '<td><table border="0" cellspacing="0" cellpadding="0" id="student">
		<tr>
		<td colspan="3" width="150px" align="center">';echo $fname, $lname; echo'</td>
		</tr>
		<tr>
		<td colspan="3" width="150px" align="center">';echo $student; echo'</td>
		</tr>
		<tr>
		<td width="40px"><div id="ajaxDiv" value="';echo $student; echo'" > </div></td>
		<td width="70px" align="center"><img src="'; echo $images, $student; echo'.jpg" width="70" height="83" /></td>
		<td width="40px"> </td>
		</tr>
		<tr>
		<td id="forms" colspan="3" width="150px" align="left"><form name="';echo $student; echo'" method="post" >';

?>
		<input name="stu_id" id="stu_id" type="hidden" readonly="true" value="<?php echo $student; ?>"/>
		<input type="checkbox" id="absent" name="<?php echo $student; ?>" onclick="ajaxFunction();" value="90"  />Absent.<br>
		<input name="class_id" id="class_id" type="hidden" readonly="true" value="<?php echo $class_id; ?>"/>
		<input type="checkbox" id="uniform" name="<?php echo $student; ?>" onclick="ajaxFunction();" value="65" />Out of Uniform.
		</form>
		</td>
		</tr>
		</table>
<?php		

$rc->MoveNext();


echo'</td>';

if(($counter % $cells_per_row) == 0) { echo '</tr>'; }
}	
$rc->Close();
echo' </body>
	</html>';
?>

Link to comment
https://forums.phpfreaks.com/topic/75543-urgent-help-form-submitting/
Share on other sites

  • 2 weeks later...

you have not set-up you xmlHttp.readyState==2 in your ajax routine. you need this this query your php page. take a closer look at xmlHttpRequest.

 

take a look at this tutorial:

http://www.tizag.com/ajaxTutorial/ajaxxmlhttprequest.php

 

look were it says "Ajax - Sending a Request for Information"

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.