Here is my Html code. What I am trying sounds simple but I am not able to do so. I am trying to use Multi page template as suggest by jquery mobile. First page I have a text box and button. User enters a value in text box and then clicks the button which should take the user to “page2” and show the search details.
My code below is taking me to “page2” but I am not able to see any search results. I inserted an alert in between and that pops up with the data. Also the back button on page2 doesn’t take me to page1?
Any pointers are greatly appreciated.
<!DOCTYPE HTML>
<html>
<head>
<title>Employee Finder</title>
<script src="jquery-mobile/jquery-1.7.2.min.js"/>
<script src="jquery-mobile/jquery.mobile-1.0a3.min.js"/>
<script src="phonegap-1.3.0.js"/>
<script src="http://ajax.microsoft.com/ajax/jquery.templates/beta1/jquery.tmpl.min.js"/>
<link href="jquery-mobile/jquery.mobile-1.0a3.min.css" rel="stylesheet" type="text/css"/>
<script>
$(document).ready(function() {
$('#findemplyoee').click(function() {
$.mobile.changePage('#page2', { transition: "slide", changeHash: true, reverse: true });
var employeeNumber = $("#employeeNumber").val();
var employeedetail = JSON.parse(... call a function here);
if(employeedetail.found)
{
$('#employeefirstName').text(employeedetail.firstName);
$('#employeelastName').text(employeedetail.lastName);
}
else
{
$('#employeeDetails').html("<p>Sorry the employee Number you entered was not found!</p>");
}
});
});
</script>
</head>
<body>
<div data-role="page" id="page1">
<div data-role="header">
<h1>Find Employee Data</h1>
</div>
<div data-role="content" id="searchDetails">
<input name="employeeNumber" type="text" id="employeeNumber"/>
<input type="button" id="findemplyoee" data-theme="b" value="Find Employee"/>
</div>
<div data-role="footer">
<h4>Page Footer</h4>
</div>
</div>
<div data-role="page" data-add-back-btn="true" id="page2">
<div data-role="header">
<h1>Page Two</h1>
</div>
<div id="employeeDetails">
<p id="employeefirstName"></p>
<p id="employeelastName"></p>
</div>
<div data-role="footer">
<h4>Page Footer</h4>
</div>
</div>
</body>
</html>
You should upgrade to jQuery Mobile 1.1!
Your example works fine: http://jsfiddle.net/eUTga/
I am pretty sure that your included jQuery version (jquery-mobile/jquery-1.7.2.min.js) is not well tested with the old jQuery Mobile (jquery-mobile/jquery.mobile-1.0a3.min.js) – or simply incompatible.
Note that the jQuery Mobile team recommends to use jQuery 1.6.4 with the latest stable (1.1.0) on the jQM download site (http://jquerymobile.com/download/).