-3

I have a table and every row has a form:

<td><input type="date" id='time'/></td>
<td><input type="text" id='info'/></td>
<td><input type="text" id='money'/></td>
<td><input type="buttond" id="submit_edit" value="edit"/></td>

The problem is I can't submit a form like this, so I need to submit this with JavaScript, and I need to submit it using the POST method. I want the POST method to do this as one row; I will change the id of the inputs later.

This is not like this question: How to submit a form with JavaScript by clicking a link?

I want to send data manually by id. The correct thing I need is like this

$(document).ready(function(){
    $("#submit_edit").click(function(){
        var time=$("#time").val();
        var info=$("#info").val();
        var money=$("#money").val();
         $.ajax(
        {
          type: "POST",
          url: "edit.php",
          data: {time:time , info:info,:money:money},
          success: function(html)
          {
            $("#edit_result").html(html).show();
          }
        });

    });
});
Community
  • 1
  • 1
Robert
  • 2,342
  • 2
  • 24
  • 41
  • there are some one write This question already has an answer here: i want to say i see that and i don't want this – Robert Feb 11 '14 at 17:36
  • i want to send data manual i mean i take the value of the inputs by id and send all of this like form – Robert Feb 11 '14 at 17:37
  • I think it may still be unclear what you're asking. Do you want to change the IDs of your input fields before the form is submitted? – Mykroft Feb 11 '14 at 17:57
  • i just want to submit this like form by POST method – Robert Feb 11 '14 at 18:00
  • and at the page when i use $_POST['input id']=value of it example if the user write at the third one ( id="money" ) 100 then when i use echo $_POST["money"]; it's print 100 – Robert Feb 11 '14 at 18:03
  • Do you not have a `
    ` tag around your code? That should happen automatically.
    – Mykroft Feb 11 '14 at 18:09
  • @Quentin please reopen the question U see how deffrence between this question and the other one it's about 3 months now and no one see the edit yet – Robert Apr 25 '14 at 12:16

2 Answers2

1

If you want to do it via ajax it's like this:

// this is the id of the form

$("#form_id").submit(function() {
  url="page.php";
  data1=$("#selector").val();
  data2="value";
  $.ajax({
        datatype:"html",
        type: "POST",
        url: url,
        data: {data1:data1,data2:data2},
        success: function(html)
        {
            alert(html);
        }
  });
});
Robert
  • 2,342
  • 2
  • 24
  • 41
Bryce Easley
  • 4,811
  • 2
  • 20
  • 22
  • how to send the data from this – Robert Feb 11 '14 at 16:03
  • @robert what do you mean? The data is the serialized version of the form. Just make sure you ad the id attribute to your form and name it form_id. – Bryce Easley Feb 11 '14 at 16:10
  • i want to send data manual i mean i take the value of the inputs by id and send all of this like form – Robert Feb 11 '14 at 17:33
  • see again the question i changed the code to be more clear what i want – Robert Feb 11 '14 at 17:45
  • @robert that's exactly what this code does. Where are you trying to send this data? Maybe if you posted the format you're expecting to receive you might get a better answer. – Mykroft Feb 11 '14 at 18:04
  • please change as the first page name is"user.php" and the action"edit.php" and when i click the edit button the script send $_POST['money']=100 at "edit.php" – Robert Feb 11 '14 at 18:11
0

you have jquery ? First if not, try this.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>

you can download http://jquery.com/download/ also

<script src="//code.jquery.com/jquery-1.10.2.min.js"></script>

Ok, now u need send a form? then ur button:

<input type="submit" name="edit" id="button_submit"/>

ur form

<form action="" method="POST" id="form">

then the jquery

$('#button_submit').click(function(){
   $('#form').submit();
});
Netzach
  • 321
  • 2
  • 13