I'm trying to pass the nationalDrugCode and id to a Javascript AJAX function
in order to save it in mysql, but the ndc doesn't get passed, only the id. Below is my while loop where the rows get displayed and the save button. I need to pass the record id as so I can do the SQL, UPDATE nationalDrugCode where id= xxx . I know the nationalDrugCode is not getting passed because I have two alerts.
On the 3rd column of data, the nationalDrugCode, you can see where I'm trying to pass it. What is happening now to the record now is the ndc value in the db is getting clobbered but the new value isn't saved. I think something is not quite right with that input line in the HTML I attach the $id to the input id so it picks it up in the getElementById . thanks,
while ($row = mysql_fetch_assoc($result)){
$id=$row['id'];
$bu=$row['bu'];
$nationalDrugCode=$row['nationalDrugCode'];
$error_flag=$row['error_flag'];
//save button on data rows
echo "<td style='border:solid black 1px;padding:2px;' align='center' nowrap>";
echo "<a href='#' onClick='saveRecord($id)' title='SaveRecord'>
<img src='../images/save-icon-trans.png' width='20' border='0'>
</a><br /><div id='txt$id' name='tag$id'><div>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$id\n";
echo "<td style='border:solid black 1px;padding:5px;'>$bu\n";
echo "<td style='border:solid black 1px;padding:5px;'><input type='text' size='15' name='nationalDrugCode$id' id='nationalDrugCode$id' value='$nationalDrugCode'>\n";
echo "<td style='border:solid black 1px;padding:5px;'>$error_flag\n";
}//while end
<script type="text/javascript">
function saveRecord(id) {
alert(id);
var answer=confirm("Save this record?")
if(!answer){return;}
get1="id="+id;
get1="&nationalDrugCode="+document.getElementByID("nationalDrugCode" + id).value;
alert(get1);
// alert(get1);
if ( window.XMLHttpRequest ) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{ // code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
if ( xmlhttp.readyState==4 && xmlhttp.status==200 && apply2All!='Y' ) {
document.getElementById("txt" + id).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.onreadystatechange=function() {
}
alert(get1);
xmlhttp.open("GET","saveRecord.php?" + get1,true);
xmlhttp.send();
}
Thanks,