-4

What would be the equivalent of using AJAX rather than sending a form in this case

<form action="" method="post">
 <div style="padding-left: 10 px:"></div>
 <input id ="datetime" style="display:none;" type="text" name="datetime" VALUE="yyyy/MM/dd HH:mm:ss" SIZE="5"   > 
 <A  HREF="#" onClick="cal.select(document.forms[0].datetime,'anchor','MM/dd/yyyy'); return false;"             
     TITLE="cal.select(document.forms['example'].datetime,'anchor','MM/dd/yyyy'); return false;" 
     NAME="anchor" ID="anchor"><i class="icon-calendar"></i>
 </A>
 <input style="font-size: Bold 8pt;" id = "done" type="submit" value="Done" />
</form>

I want to use the AJAX post to get my new variables rather than sending the form.

2
  • Why don't you read the documentation for $.ajax and find out ?
    – adeneo
    Commented Apr 8, 2013 at 20:24
  • Dunno...I argue you don't even know what you're talking about. Commented May 2, 2017 at 12:43

1 Answer 1

0

It would just be

$("#done").click(function() {
    $.post("/",{"datetime": $("#datetime").val()});
    return false;
})

More about $.post: http://api.jquery.com/jQuery.post/

4
  • Would i put this into another JS file? Also, I wouldn't need to have a submit input would I?
    – Talentz
    Commented Apr 8, 2013 at 20:27
  • No, just make sure you include jQuery and put it in a <script> tag at the end of the page. Commented Apr 8, 2013 at 20:28
  • Should I still have the input tag for the submit?
    – Talentz
    Commented Apr 8, 2013 at 20:29
  • Yes, I updated my answer (though you probably want to look at the duplicate question notice) Commented Apr 8, 2013 at 20:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.