Search code examples
phpjquerybuttonsubmitsend

How to make button to post data with jQuery


Using Google and this site, I've made a simple form to send data with jQuery.

My HTML code:

<a href="javascript:AddPoke('{news-id}', 'poke')">ADD</a>
<div class="area"></div>

And jQuery:

function AddPoke(id, action){
 var response = $('#dle-poke').val()
  $.post(dle_root + 'engine/ajax/poke.php', {id: id, text: response, action: action},
   function(data){
    if (data == 'ok') {DLEalert(dle_p_send_ok, dle_info);}
    else {DLEalert(data, dle_info);}
});

$('.area').append("<div id='dlepopup'><textarea name='dle-poke' id='dle-poke'></textarea></div>");
$("#dlepopup").slideDown(700);
};

The problem is that I don't know how to make a send or submit button to post this data! I am very inexperienced with jQuery and I would appreciate any help!


Solution

  • HTML CODE:

    <input type="text" name="first_name" id="first_name" />
    <input type="text" name="last_name" id="last_name" />
    <a href="javascript:void(0);" onclick="javascript:submit_value();" >Add </a>
    

    Javascript Code:

    <script>
        function submit_value()
        {
           alert($('#first_name').val());
           alert($('#last_name').val());
        }
    </script>
    

    When you have enter any text in textfields then click on ADD link to display the alert message here display the text as you have write in textfileds.

    Note: Please include the latest jQuery file in head tag.