i have a div with 2 checkbox items ( Employee / Teacher ) and a button with on click function that alerts the value of the chosen check items through javascript, and then i wanna assign these values to a variable that i want to use in php, the result is always Teacher ( even thought in the alert i get the correct value ex: Employee ), what am i doing wrong? my code is the following :
<div class="form-group">
<label style="text-align: left;" class="control-label col-sm-3">Type</label>
<div class="col-sm-3">
Employee<input type="checkbox" name='checkbox0' value="Employee" >
Teacher<input type="checkbox" name='checkbox1' value="Teacher" >
<input type="button" id="envoyer" value="Envoyer Reponse"/>
</div>
<script>
$("#envoyer").click(function(e) {
var myArray = [];
$(":checkbox:checked").each(function() {
myArray.push(this.value);
});
alert(myArray.join(","));
var a=myArray.join(",");
if (a=='Employee') { <?php $a='Employee'; ?> } else if (a=='Teacher') { <?php $a='Teacher'; ?> }
});
</script>
</div> <!-- /.form-group -->
<?php echo $a; ?>
Aucun commentaire:
Enregistrer un commentaire