jquery mobile form submit. Simple form that takes user to page on form submit
I'm struggling with a form submit in jquery mobile and the api doesn't show any useful examples.
Here is my html:
<div data-role="page" id="test" data-id="test">
<div data-role="content">
<form id="form1">
<div id="titleDiv" data-role="fieldcontain">
<label id="titlelabel" for="title">Title *</label>
<select id="title" name="title">
<option value="null">Please select a title</option>
<option value="mr">Mr</option>
<option value="miss">Miss</option>
<option value="mrs">Mrs</option>
<option value="ms">Ms</option>
<option value="dr">Dr</option>
</select>
</div>
<div id="submitDiv" data-role=开发者_高级运维"fieldcontain">
<input type="submit" value="Submit Form" data-inline="true"/>
</div>
</form>
</div>
</div>
<div data-role="page" id="test" data-id="test">
<p>form confirmation page</p>
</div>
and here is my javascript:
$('div').live('pageshow',function(event, ui) {
$('#form1').submit(function() {
alert('test');
// Submit the form
// $.post("/forms/requestProcessor.php", form1Var.serialize(), function(data){
// });
$.mobile.changePage($("#test"), "slideUp");
return false;
});
});
On submit, I want it to show an alert then take the user to a page. At the moment, that code shows the alert 3 times the does nothing. Any ideas what is wrong with it?
A problem is that you're re-using the test
id. Give the second page a different id and changePage
to that id will work. Also it would be better to omit the pageshow
or restrict it to #test
rather than all the divs in your page.
精彩评论