I'm trying to add the possibility to delete a selected element from a dropdown menu that is linked to a text field. These elements source is the XML file. I added a DELETE button next to the dropdown menu, so that you can select the name you want, then click DELETE and it needs to delete the selected Signature element in the XML file with the "name" attribute that fits with the value of the dropdown menu.
My jQuery code on the HTML page :
<script type="text/javascript">
$( document ).ready(function() {
$('#deletenode').click(function(){
if (confirm('Do you want to delete this name?')) {
alert('Delete done');
$.ajax({url: 'delete.php'});
return true;
}
else
{
alert('Delete cancelled');
return false;
}
});
});
</script>
My PHP script for deleting the node :
<?php
$xml = simplexml_load_file("signatures.xml");
$name = $_POST['nom'];
$signs = $xml->xpath('//Signature[Nom = "'.$name.'"]');
$xml -> SignaturesParent -> removeChild($signs);
?>
My XML structure :
<SignaturesParent>
<Signature name="John Doe">
<Nom></Nom>
<Title></Title>
</Signature>
<Signature name="John Foo">
<Nom></Nom>
<Title></Title>
</Signature>
</SignaturesParent>
What is not working, is that nothing is getting deleted (obviously). What's wrong in my code? I tried to explain it as simple as possible. Thanks!