1

i want to send all the input fields of the form to process/do_submitattendance.php, where i can use the to store in the database. However i am having trouble doing this. My jQuery code is-

 <script type="text/javascript">
    $("#submitattendance").submit(function(){

        var_form_data=$(this).serialize();
        $.ajax({
            type: "POST",
            url: "process/do_submitattendance.php",
            data: var_form_data,
            success: function(msg){
                alert("data saved" + msg);

            });

    });       
</script>

submitattendance is the ID of the form element.

George Cummins
  • 28,485
  • 8
  • 71
  • 90
Tango Tango
  • 13
  • 1
  • 3

3 Answers3

1

I'm guessing the form is submitting, and you'll have to prevent the default submit action:

<script type="text/javascript">
  $(function() {
    $("#submitattendance").on('submit', function(e){
        e.preventDefault();
        $.ajax({
           type: "POST",
           url : "process/do_submitattendance.php",
           data: $(this).serialize()
        }).done(function(msg) {
            alert("data saved" + msg);
        });
    });
  });
</script>
adeneo
  • 312,895
  • 29
  • 395
  • 388
  • on clicking the submit button it is taking the browser to http://localhost/realbhs/process/do_submitattendance.php?date=ee&0913301023=on&223232323=on&register_name=bhs_1_1_1_A_chem&submit_attendance=Submit – Tango Tango Mar 29 '13 at 09:34
  • Did you include jQuery? Open the console (F12) and look for errors. – adeneo Mar 29 '13 at 09:52
  • @TangoTango - You're using a version of jQuery that is too old, it's on 2.0 now and you're using a version below 1.7. – adeneo Mar 29 '13 at 10:43
  • I Am using 1.9.1 which version should i use ? i cant find the 2.0 version – Tango Tango Mar 29 '13 at 11:21
  • In 1.9.1 this is not an issue, but if `.on()` does'nt exist you are using an older version. – adeneo Mar 29 '13 at 11:38
  • ok now i removed that version and using another version, and now it is showing no error in console however it is still taking the page to the url http://localhost/realbhs/process/do_submitattendance.php?date=ww&0913301023=on&register_name=bhs_1_1_1_A_chem&submit_attendance=Submit @adeneo – Tango Tango Mar 29 '13 at 12:28
0
var var_form_data=$(this).serialize();

is all i can find, or there must be an error in your code somewhere else. you can look in your chrome console to see if there is an error (f12). also add return false; to stop the form submitting itself.

Joel Harkes
  • 10,975
  • 3
  • 46
  • 65
0

Why don't you try to pass values through session?

By using session you can pass the values from one page to anyother pages you want.

the typical code looks like this:

Mainpage.php

 <?php
    session_start(); // You should start session 
    $_SESSION['UserName']="YourTextfield"; 
    ?>

SecondPage.php

<?php
session_start();
$var = $_SESSION['UserName'];
?>

After you saved the data...then you need reset the session

$_SESSION['UserName']="";

That's what I usually use. and I hope it will help you...

reaz
  • 735
  • 1
  • 10
  • 20
  • so you take everything in session before storing it into database ? That's horrible – Tango Tango Mar 29 '13 at 09:36
  • Yes, and we usually create our own session we call it ( SessionFacade) . but the way above is also a good way to pass those values from one page to another ( create multiple sessions according to the number of fields and use them in that page where the database functions are in. Then reset the session. and I think what you need is just passing values form one page to anther. – reaz Mar 29 '13 at 09:41