Joel James
Joel James

Reputation: 3938

jQuery mobile passing parameter from one page to another

I am currently using a form to navigate and pass form parameters from one one page to another and through a query string.

FirstPage form code

<form name="input" action="new_page.html" method="get">
Username: <input type="text" name="user" />
<input type="submit" value="Submit" />
</form>

In the new page I am trying to get the query-string value using document.URL. When the old page directs to the new page only the body contents of the new page are executed. The script files are not executed in the new page. Thus, I am not able to grab the query string values in the new page.

The process of passing parameters through form from one page to another works well for a regular HTML page, but does not work in case of jQuery Mobile.

Can any one suggest me a better way of passing parameters from one jQuery Mobile page to another. Any help is appreciated.

Upvotes: 2

Views: 7291

Answers (3)

Shasak
Shasak

Reputation: 820

If you redirect from a jquery mobile page the new page is loaded using ajax, so JS for the new page won't work using the $(document).ready();

$(document).ready(function(){
      //your awesome JS here won't work!
});

so use this instead:

$(document).bind('pageinit',function(event){
         //the same JS here will work!

});

Now your JS should work (at least did for me!). for further info go here. Hope this helps!

Upvotes: 0

Leon
Leon

Reputation: 4532

Regarding passing querystring parameters in JQM, have a look at my previous answer with code samples.

Hope this helps!

Upvotes: 0

Jasper
Jasper

Reputation: 76003

Regarding your scripts not executing when you change pages: jQueryMobile page events not firing when navigating to a different html page

jQuery Mobile uses AJAX to pull new pages into the DOM, which is something you'll have to get used to for creating jQuery Mobile websites. This means that code that is supposed to run on document.ready or window.load should be bound to other events like: pagecreate, pageshow, pageinit. Here's jQuery Mobile's documentation on events (which can be quite enlightening): http://jquerymobile.com/demos/1.0/docs/api/events.html (Note that page-events start about half-way down).

Upvotes: 1

Related Questions