I am trying to change page on a form submit in Jquery, however, it is not working. It slides to show the same page instead of navigating to the target page. Below is the code. Any insights please? I tried using "#mainpage" , "index.html#mainpage" as well and still the same result. Link: jsfiddle.net/7yRph/1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Multi-page template</title>
<link rel="stylesheet" href="jquery.mobile-1.0.min.css" />
<script src="jquery-1.6.4.min.js"></script>
<script src="jquery.mobile-1.0.min.js"></script>
<script type="text/javascript">
$('#launchpage').live('pagecreate',function(event) {
$('#fhome').submit( function () {
$.mobile.changePage("mainpage");
});
});
</script>
</head>
<body>
<!-- PAGE: launchpage -->
<div data-role="page" id="launchpage">
<div data-role="header">
<h1 data-theme="g" >Personal Details</h1>
</div><!-- /header -->
<div data-role="content" >
<div class="content-primary">
<form id="fhome" method="POST" >
<div data-role="none">
<p> Lets begin: </p>
</div>
<br/>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal" >
<legend>Are you providing information about yourself?</legend>
<label for="launchradioyes">Yes</label>
<input type="radio" name="radio-choice" id="launchradioyes" value="yes" />
<label for="launchradiono">No</label>
<input type="radio" name="radio-choice" id="launchradiono" value="no" />
</fieldset>
</div>
<input type="submit" value="Next" data-theme="a" />
<br/>
</form>
</div><!-- /content -->
<div data-role="footer" data-theme="d">
</div><!-- /footer -->
</div><!-- /launch page -->
<!-- PAGE: mainpage -->
<div data-role="page" id="mainpage">
<div data-role="header">
<h1>Testing page navigation II</h1>
</div><!-- /header -->
<div data-role="content" >
<div class="content-primary">
<div data-role="none">
<label for="idprimary">ID:</label>
<input type="tel" name="idprimary" id="idprimary" value="" />
</div>
<br/>
</div><!-- /content -->
<div data-role="footer" data-theme="d">
</div><!-- /footer -->
</div><!-- /page one -->
</body>
</html>
You are missing your action attribute in your form tag. This often breaks functionality of forms in browsers. Try this:
It shouldn’t negatively affect your code as you hijack the submit action anyway.
UPDATE
Also, you are missing your closing
</form>tag and another closing</div>tag after that.Do you need to use a submit button? Would it work to use a button and its corresponding click event?
http://jsfiddle.net/shanabus/7yRph/3/
UPDATE 2, working with form submit
After you resolve the closing tags, add the
preventDefaultmethod call and thedata-ajax="false"attribute as outlined here in the docs.example: http://jsfiddle.net/shanabus/7yRph/9/