I have a form and I need to pass it to PHP page this is my HTML part ,
for ($j=0;$j<2;$j++) {
?>
<tr><th><div class="col-xs-2">
<input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">
</div></td>
<?php
for ($s=1;$s<=count($days)-6;$s++) {
?>
<td><div class="col-xs-2">
<input class="form-control input-lg" name="Subject[]" id="Subject<?php echo $j.$s ?>" type="text" value="" style="width:120px; height:30px;">
<input class="form-control input-lg" name="Day[]" id="inputlg" type="hidden" value="<?php echo $days[$s]; ?>" style="width:120px; height:30px;">
</div></td>
<?php
}
echo "</tr>";
}
and this is my jquery code ,
$(document).ready(function() {
$("#btnSubmit").click(function() {
var Sub = $('[name=Subject]').val();
$.ajax({
url: 'sample.php',
type: 'post',
data: 'Subject=' + Sub,
success: function(data) {
alert(data);
},
error: function(data) {
alert("ERRRR");
}
})
});
});
and this is my PHP code ,
$Sub = $_POST['Subject'];
print_r($Sub);
It actually sending the value but I don't get any response. I am stucking with it any help will be really appreciated .
EDIT :
I have heared map or each function can do this but I dont know how to use the functions
for ($j=0;$j<2;$j++) {
?>
<form>
<tr><th><div class="col-xs-2">
<input class="form-control input-lg" name="Time[]" id="inputlg" type="text" value="" style="width:120px; height:30px;">
</div></td>
<?php
for ($s=1;$s<=count($days)-6;$s++) {
?>
<td><div class="col-xs-2">
<input class="form-control input-lg" name="Subject[]" id="Subject<?php echo $j.$s ?>" type="text" value="" style="width:120px; height:30px;">
<input class="form-control input-lg" name="Day[]" id="inputlg" type="hidden" value="<?php echo $days[$s]; ?>" style="width:120px; height:30px;">
</div>
</td>
<?php
}
echo "</tr>";
} ?>
<input type="button" id="btnSubmit" value="sub">
</form>
And Script is
<script type="text/javascript">
$(document).ready(function() {
$("#btnSubmit").click(function() {
var str = $( "form" ).serialize();
$.ajax({
url: 'newpage.php',
type: 'post',
data: str,
success: function(data) {
alert(data);
},
error: function(data) {
alert("ERRRR");
}
})
});
});
Using this you will get whole inputs array.