i am using the following form:
<form id="dataForm" method="post">
<h2 id="formheader"> Update Product Description</h2>
<div>
<label>Product Name:</label>
<input class="inputForm" id="orginalName" type="text" name="Name">
</div>
<div>
<label>New Description:</label>
<input class="inputForm" id="newDescription" type="text" name="newDescription">
</div>
<div id="theSubmit">
<button id="editDescription">Submit</button>
</div>
</form>
and using the following simple php, which when used with action=editProductDes.php
works...
$Name = $_POST['Name'];
$Description = $_POST['newDescription'];
if($Name !="" && $Description !=""){
$sql = "UPDATE PRODUCTS SET P_Description = '$Description' WHERE P_NAME = '$Name'";
$conn->exec($sql);
and then when i use the following java script the data is not passed through and I cannot see why as I have a similar function and form where the JavaScript works fine, can anyone see why the data is not passing through?
function editDescription(){
xmlhttp = new XMLHttpRequest();
var name = document.getElementById("orginalName");
var Description = document.getElementById("newDescription");
var data_seen = false;
// this is a flag to record whether any data has been seen. Used in the guard ofthe alert statement.
if (name.value !="" && Description.value !="" ){
data_seen = true;
xmlhttp.open("POST","editDescription.PHP",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("Name=" + name.value + "&Description=" + Description.value);
}
if (!data_seen) {
alert("please enter some data");
}
}
submitButton = document.getElementById("editDescription");
submitButton.addEventListener("click", editDescription);