I need a little help with this code:
<script type="text/javascript">
$(document).ready(function(){
$("#btnGrp").click(function(){
var dataString = 'IDAtelier='+ $("#IDAtelier").val() + '&Dates=' + $("#Dates").val();
$.ajax
({
type: "POST",
url: "ajaxAjouterGroupe.php",
data: dataString,
cache: false,
success: function(html)
{
$("#DatesList").html(html);
}
});
});
});
</script>
HTML:
<form name="Dates" id="Dates" action="traitementDates.php" method="post">
<p class="inscHeader">Dates</p>
<div id="DatesList">
<?php GetGroupBody(htmlentities($_POST['IDAtelier']));?>
</div>
<button type="button" id="btnGrp" name="btnGrp">Ajouter un groupe</button>
<input type="submit" value="Terminer l'ajout de l'atelier" /><br />
<input type="hidden" id="IDAtelier" name="IDAtelier" value="<?php GetAtelierID();?>" />
</form>
PHP(Function to get "Rencontres" linked to "Atelier"):
function GetGroupBody($IDAtelier)
{
echo '<b><i>Groupe</i></b><br/>';
global $Cnn;
$req = $Cnn->prepare("SELECT * FROM Rencontres WHERE IDAtelier = ".$IDAtelier."");
$req->execute();
while($data = $req->fetch())
{
echo '<label>'.$data['Titre'].': </label><input type="text" name="Dates[]" id="Dates[]" /><br/>';
}
$req->closeCursor();
}
I want to post my inputs with ID="Dates[]"
to my ajax but this doesn't seem to work. Any idea how to solve this ?
You seem to have two problems:
#Dates
but your ID is Dates[]
. You've lost the square brackets from it. You have to escape them for selector syntax (because they are otherwise an attribute selector), and you have to escape the escape character (because they are other a JavaScript escape character. $('#Dates\\[\\]')
.You should avoid using []
in IDs, they complicate things terribly.