I am developing a slider to set my budget and would like to achieve the value which I set in slider1.php. However, when I tried using the code below, I encountered an error "Notice: Undefined index: slideStatus in C:\xampp\htdocs\1204763e\slider1\slider1.php on line 4 Thank you , says the PHP file"
In slide.php, I inserted this set of code:
<html>
<head>
<script language="JavaScript" type="text/javascript">
function ajax_post(val){
var hr = new XMLHttpRequest();
var url = "slider1.php";
var ss = document.getElementById('sliderStatus').innerHTML = val;
var vars = "sliderStatus="+ss;
hr.open("POST", url, true);
hr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
hr.onreadystatechange = function() {
if(hr.readyState == 4 && hr.status == 200) {
var return_data = hr.responseText;
document.getElementById("status").innerHTML = return_data;
}
}
// Send the data to PHP now... and wait for response to update the status div
hr.send(vars); // Actually execute the request
document.getElementById("status").innerHTML = "processing...";
}
</script>
</head>
<body>
<h2>Ajax Post to PHP and Get Return Data</h2>
<input type="range" name="slide" min="0" max="100" value="50" step="2" onChange="ajax_post(this.value)" />
<br /><br />
<span id="sliderStatus">50</span>
<br/><br/>
<div id="status"></div>
</body>
</html>
In slider1.php, I inserted this set of code:
<?php
echo 'Thank you '. $_GET['slideStatus'] . ', says the PHP file';
?>