Post some field values using ajax before submitting from submit button

Seeker

Can I post some values using ajax before submitting fields from submit button ?

I'm using the following code. It reaches success but I'm not able to get the posted data. Any clue for this ? Your help/review will be greatly appreciated. Thanks!

function auto_fill(){  

        var that = $(this),
            url = './auto_fill.php',
            type = that.attr('method'),
            data = {};

        that.find('[name]').each(function(index,value){
            var that =$(this),
                name =that.attr('name'),
                value = that.val();
                data[name] = value;
        }); 

        $.ajax({
            url: url,
            type: type,
            data: data,
            success: function(response) {
                        document.getElementById("f_name").value="<?php echo $name ?>";
                        document.getElementById("phn_no").value="<?php echo $phn_num ?>";

            }
        });

        return false;
    }
Dexpras

Try this

function auto_fill(){
  $.getJSON("./auto_fill.php?id_num=" + $("#id_num").val(),
        function(data){
          $.each(data, function(i,item){
            if (item.field == "first_name") {
              $("#f_name").val(item.value);
            } else if (item.field == "phonenum") {
              $("#phn_no").val(item.value); 
            } 
          });
        });
}

auto_fill.php

$id = $_GET['id_num'];

//build the JSON array for return
$json = array(array('field' => 'first_name', 
                    'value' => 'Your name'),

              array('field' => 'phonenumber', 
                    'value' => $phn),
              array('field' => 'somethinglikeDiscription', 
                    'value' => 'You entered ID as '.$id));
echo json_encode($json );

you can pass any variable to this values by this JSON array.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Stop Submit Button From Submitting Using JQuery

From Dev

Submitting a form (post, NOT ajax) with some additional parameters

From Dev

Submitting without submit button

From Dev

Submit button not submitting on a form

From Dev

PHP post submit not submitting

From Dev

how to submit the form values using ajax call, without using submit button

From Dev

submitting form to PHP page without reloading using the submit button

From Dev

Only can post values with one submit button

From Dev

submitting form with jQuery/AJAX, cant stop page from refreshing on submit?

From Dev

form is not submitting when some field is empty on using react

From Dev

form is not submitting when some field is empty on using react

From Dev

validate form using jquery validation before submitting through ajax

From Dev

Submitting a form with multiple submit values

From Dev

Submit form using ajax, and then disable button

From Dev

Submit with post method using jquery .ajax()

From Dev

validate ajax submit post method before sending data

From Dev

form submit using jquery ajax with button type not submit type

From Dev

Submitting Form using AJAX won't POST to database

From Dev

AJAX submit on multiple input field w/ edit & save button

From Dev

AJAX: Disabling submit button until username field is filled with email

From Dev

stop button_tag type:submit from submitting an empty button parameter

From Dev

Make a submit button POST and AJAX call same time?

From Dev

Form submit button stays disabled after ajax post

From Dev

Make a submit button POST and AJAX call same time?

From Dev

Not getting any output from submit button on select box using jquery,Ajax

From Dev

checking values before submitting form

From Dev

Ajax validation before submit

From Dev

Ajax validation before submit

From Dev

Using jquery ajax post to submit a POST request in Phoenix Framework

Related Related

  1. 1

    Stop Submit Button From Submitting Using JQuery

  2. 2

    Submitting a form (post, NOT ajax) with some additional parameters

  3. 3

    Submitting without submit button

  4. 4

    Submit button not submitting on a form

  5. 5

    PHP post submit not submitting

  6. 6

    how to submit the form values using ajax call, without using submit button

  7. 7

    submitting form to PHP page without reloading using the submit button

  8. 8

    Only can post values with one submit button

  9. 9

    submitting form with jQuery/AJAX, cant stop page from refreshing on submit?

  10. 10

    form is not submitting when some field is empty on using react

  11. 11

    form is not submitting when some field is empty on using react

  12. 12

    validate form using jquery validation before submitting through ajax

  13. 13

    Submitting a form with multiple submit values

  14. 14

    Submit form using ajax, and then disable button

  15. 15

    Submit with post method using jquery .ajax()

  16. 16

    validate ajax submit post method before sending data

  17. 17

    form submit using jquery ajax with button type not submit type

  18. 18

    Submitting Form using AJAX won't POST to database

  19. 19

    AJAX submit on multiple input field w/ edit & save button

  20. 20

    AJAX: Disabling submit button until username field is filled with email

  21. 21

    stop button_tag type:submit from submitting an empty button parameter

  22. 22

    Make a submit button POST and AJAX call same time?

  23. 23

    Form submit button stays disabled after ajax post

  24. 24

    Make a submit button POST and AJAX call same time?

  25. 25

    Not getting any output from submit button on select box using jquery,Ajax

  26. 26

    checking values before submitting form

  27. 27

    Ajax validation before submit

  28. 28

    Ajax validation before submit

  29. 29

    Using jquery ajax post to submit a POST request in Phoenix Framework

HotTag

Archive