-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 ? 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/

Sign up to request clarification or add additional context in comments.

4 Comments

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.