I have a script that allows me to select an item from a dropdown, and depending on the choice of complete input text. This part works, except when I want to validate the form and save the data, input text are not recognized. Can you explain me why I am having problem with my form submission?
Here is my code:
The javascript code:
HTML Code:
<script type='text/javascript'>
function getXhr(){
var xhr = null;
if(window.XMLHttpRequest) // Firefox and other
xhr = new XMLHttpRequest();
else if(window.ActiveXObject){ // Internet Explorer
try {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
}
else { // XMLHttpRequest not supported by your browser
alert("Your browser does not support XMLHTTPRequest objects...");
xhr = false;
}
return xhr;
}
/**
* Method will be called on click of button
*/
function go1(){
var xhr = getXhr();
// It defined what will we do when we have the answer
xhr.onreadystatechange = function(){
// We do something if we have received everything and that the server is ok
if(xhr.readyState == 4 && xhr.status == 200){
theselect = xhr.responseText;
// It uses innerHTML for adding options to the list
document.getElementById('hour').innerHTML = theselect;
}
}
// Here we will see how to post
xhr.open("POST","ajax_journey.php",true);
// do not forget it for post
xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
// do not forget to post the arguments
// Here, the id of the author
sel = document.getElementById('journey');
id_journey = sel.options[sel.selectedIndex].value;
xhr.send("id_journey="+id_journey);
}
</script>
I took the example of linked lists, the problem may be there ...
My page ajax_journey.php
PHP Code:
if(isset($_POST["id_journey"]))
{
$res = mysql_query(" SELECT debut_journey, fin_journey, hour_works
FROM journey
WHERE id_journey=".$_POST["id_journey"]);
$row = mysql_fetch_assoc($res);
if ($row['debut_journey'] != "00:00:00") { $deb_read = 'readonly="readonly"'; } else { $deb_read = ""; }
if ($row['fin_journey'] != "00:00:00") { $fin_read = 'readonly="readonly"'; } else { $fin_read = ""; }
if ($row['hour_works'] != "00:00:00") { $trav_read = 'readonly="readonly"'; } else { $trav_read = ""; }
echo '<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td width="160px">Start Time :</td>
<td><input type="text" name="time_start" value='.substr($row['start_journey'],0, 5).' size="4" class="form" style="text-align: center;" /></td>
</tr>
<tr style="height: 5px;"></tr>
<tr>
<td align="left">End Time :</td>
<td><input type="text" name="time_end" value='.substr($row['fin_journey'],0, 5).' size="4" class="form" style="text-align: center;" /></td>
</tr>
<tr style="height: 5px;"></tr>
<tr>
<td align="left">Time worked :</td>
<td><input type="text" name="time_work" value='.substr($row['time_work'],0, 5).' size="4" class="form" style="text-align: center;" /></td>
</tr>
</table>';
}
Bookmarks