SilverNodashi
Expert Member
Hi,
I hope someone can help me. I am trying to post drop down selection code to a PHP scrip using AJAX, but it's not being sent to the PHP script.
Here's the AJAX code:
The users_add.php script has the following debug code:
And this is the output when submitting the form data:
I also added a debut routine to see what the SQL command would like like, and somehow the two select options get concatenated but I can't see how / where?
Does anyone know what would cause this?
I hope someone can help me. I am trying to post drop down selection code to a PHP scrip using AJAX, but it's not being sent to the PHP script.
Here's the AJAX code:
JavaScript:
<script>
function createNew() {
$("#add-more").hide();
var data =
`<tr class="table-row" id="new_row_ajax">
<td contenteditable="true" id="username" onBlur="addToHiddenField(this,\'username\')" onClick="editRow(this);"></td>
<td contenteditable="true" id="password" onBlur="addToHiddenField(this,\'password\')"onClick="editRow(this);"></td>
<td contenteditable="true" id="email" onBlur="addToHiddenField(this,\'email\')" onClick="editRow(this);"></td>
<td contenteditable="true" id="status" onBlur="addToHiddenField(this,\'status\')" onClick="editRow(this);"><select name="status"><option>Active</option><option>Inactive</option></select></td>
<td contenteditable="true" id="branch" onBlur="addToHiddenField(this,\'branch\')" onClick="editRow(this);"></td>
<td contenteditable="true" id="own_apps" onBlur="addToHiddenField(this,\'own_apps\')" onClick="editRow(this);"><select name="own_apps"><option value="No">No</option><option value="Yes">Yes</option></select></td>
<td contenteditable="true" id="branch_apps" onBlur="addToHiddenField(this,\'branch_apps\')" onClick="editRow(this);"><select name="branch_apps"><option value="No">No</option><option value="Yes">Yes</option></select></td>
<td contenteditable="true" id="all_apps" onBlur="addToHiddenField(this,\'all_apps\')" onClick="editRow(this);"><select name="all_apps"><option value="No">No</option><option value="Yes">Yes</option></select></td>
<td>
<input type="hidden" id="username" />
<input type="hidden" id="password" />
<span id="confirmAdd">
<a onClick="addToDatabase()" class="ajax-action-links">Save</a> /
<a onclick="cancelAdd();" class="ajax-action-links">Cancel</a>
</span>
</td>
</tr>`;
$("#table-body").append(data);
}
function cancelAdd() {
$("#add-more").show();
$("#new_row_ajax").remove();
}
function editRow(editableObj) {
$(editableObj).css("background","#FFF");
}
function addToDatabase() {
var username = $("#username").val();
var password = $("#password").val();
var email = $("#email").val();
var status = $("#status").val();
var branch = $("#branch").val();
var own_apps = $("#own_apps").val();
var branch_apps = $("#branch_apps").val();
var all_apps = $("#all_apps").val();
$("#confirmAdd").html('<img src="loaderIcon.gif" />');
$.ajax({
url: "users_add.php",
type: "POST",
data:'username='+username+'&password='+password+'&email='+email+'&status='+status+'&branch='+branch+'&own_apps='+own_apps+'&branch_apps='+branch_apps+'&all_apps='+all_apps,
success: function(data){
$("#new_row_ajax").remove();
$("#add-more").show();
$("#table-body").append(data);
}
});
}
function addToHiddenField(addColumn,hiddenField) {
var columnValue = $(addColumn).text();
$("#"+hiddenField).val(columnValue);
}
</script>
The users_add.php script has the following debug code:
PHP:
$DEBUG = 'Off'; // On or Off
if ($DEBUG =='On'){
echo '<table>';
echo "<pre>";
print_r($_POST);
echo "</pre>";
echo "</table>";
}
And this is the output when submitting the form data:
Code:
Array
(
[username] => John
[password] => Doe
[email] => [email protected]
[status] => ActiveInactive
[branch] => HeadOffice
[own_apps] =>
[branch_apps] =>
[all_apps] =>
)
I also added a debut routine to see what the SQL command would like like, and somehow the two select options get concatenated but I can't see how / where?
Rich (BB code):
INSERT INTO users (username,password,email,status,branch,own_apps,branch_apps,all_apps) VALUES ('John','Doe','[email protected]','ActiveInactive','HeadOffice','','','')
Does anyone know what would cause this?