1

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

4
  • Do you get any error in console? Commented Jul 22, 2015 at 5:45
  • No it show me succes alert, Status 200 OK Commented Jul 22, 2015 at 5:48
  • Do you see the data passed to server in network request Commented Jul 22, 2015 at 5:48
  • @Tushar I have array of Subjects like Subjects[0],Subjects[1] ....... I need to send all these that what the problem . I can send a single value by this code Commented Jul 22, 2015 at 5:51

1 Answer 1

1
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.

Sign up to request clarification or add additional context in comments.

1 Comment

thnx that what exactly I wanted

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.