简体   繁体   中英

Send data to Parse once the “submit” button has been clicked

I'd like to use JavaScript/jQuery Mobile to capture a date inputted by the user, and then once the submit button is pressed send it to the parse.com data cloud.

Using the below code I can send the data to parse automatically without issue, but I'm unsure how to trigger this event by the submit button being clicked instead.

How do I link the two together?

<!-- Home -->
<div data-role="page" id="page1">
    <div data-role="content">
        <form id="dansform" action="dansform" method="POST" class="dansform">
            <div data-role="fieldcontain" class="date">
                <label for="date">
                    Date
                </label>
                <input name="date" id="date" placeholder="date" value="Select today's date"
                type="date" data-mini="true">
            </div>
            <input id="submit" type="submit" data-theme="c" value="Submit" data-mini="true"
            class="submit">
        </form>
    </div>
</div>


<script type="text/javascript">

Parse.initialize("X", "X");

  var TestObject = Parse.Object.extend("TestObject");
  var testObject = new TestObject();
  testObject.save({foo: "bar"}, {
    success: function(object) {
      alert("yay! it worked");
    }
  });

</script>

The solution is the onsubmit event.

   <form onsubmit="dosomthing(); return false;" id="dansform" action="dansform" method="POST" class="dansform">
        <div data-role="fieldcontain" class="date">
            <label for="date">
                Date
            </label>
            <input name="date" id="date" placeholder="date" value="Select today's date"
            type="date" data-mini="true">
        </div>
        <input id="submit" type="submit" data-theme="c" value="Submit" data-mini="true"
        class="submit">
    </form>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM