Question

I'm trying to develop a mobile app using Phonegap and jQuery Mobile. the problem that i have is that pages don't change when events are triggred. Here is the code of pages and jQuery:

<div id="deviceready" data-role="page">
    <div data-role="header">Header</div>
    <div role="main" class="ui-content">
        <form>
            <label for="username">User name:</label>
            <input name="username" id="username" value="" type="text">
            <label for="password">User name:</label>
            <input name="password" id="password" value="" type="password">
            <button id="submit-login" class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-user">Login</button>
        </form>
    </div>
    <div data-role="footer">Footer</div>
</div>
<div id="formResults" data-role="page">
    <div data-role="header">Header</div>
    <div>Hello from success</div>
    <div data-role="footer">Footer</div>
</div>
<script type="text/javascript">
    $('#submit-login').click(function() {
        $(':mobile-pagecontainer').pagecontainer('change', '#formResults', {
            reload: true
        });
    });
</script>

The navigation don't work between pages

Was it helpful?

Solution

I think your action in your form is being triggered to reload itself. Have a look at this Demo http://jsfiddle.net/JuY9L/ Where I have changed the code of the form so that it returns an empty action.

HTML:

<div id="deviceready" data-role="page">
    <div data-role="header">Header</div>
    <div role="main" class="ui-content">
        <form action="javascript:void(0);">
            <label for="username">User name:</label>
            <input name="username" id="username" value="" type="text" />
            <label for="password">User name:</label>
            <input name="password" id="password" value="" type="password" />
            <button id="submit-login" class="ui-btn ui-shadow ui-corner-all ui-btn-icon-left ui-icon-user">Login</button>
        </form>
    </div>
    <div data-role="footer">Footer</div>
</div>
<div id="formResults" data-role="page">
    <div data-role="header">Header</div>
    <div>Hello from success</div>
    <div data-role="footer">Footer</div>
</div>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top