Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8625107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:42:02+00:00 2026-06-12T07:42:02+00:00

Tried to bind submit event (or click or whatever) to an element within a

  • 0

Tried to bind submit event (or click or whatever) to an element within a jQuery mobile page. What I wanted to do is get the value from an input within an form element within a jQuery page and store it in cookies/localStorage. Every time I come back to this page I want to restore the input field.

Currently I ended up in using this script:

    $('.pageClassSelector').live('pageinit', function (e) {

        $('.classSelector').submit(function () {
            var q = $('.inputClassSelector').val();
            // store to localStorage ...
        });

    // load from localStorage ...
    $('.q').val(lastSearchString);

    });

This approach is documented there http://jquerymobile.com/test/docs/api/events.html

Since it seems possible that identical pages are hold in the DOM, ID selectors are not quite useful. My problem now is that everytime I navigate to this page the submit event is bound again and thus results in storing DIFFERENT (!) values. The submit event seems to be fired multiple times and much more interesting with the value before last.

Am I doing anything completly wrong? Any hints how to do scripting in jquery mobile properly?

TRY1:

I placed now the submit event binding within the pagebeforeshow event like so:

$('#PageId').on('pagebeforeshow', function (e) {
    $('.classSelector').on('submit', function () {
            var q = $('.q').val();
            alert('stored: ' + q);         
    }
    $('.q').val(lastSearchString);
}

But the value going to be stored is still the value before last, when I was navigating the page before. The first time it works as it should.

TRY2:

This is what I have now and it looks like it does that what I want. I select now the current page and select only the form which is a child of this page.
Is this good practice?

$('div:jqmData(id="PageId")').on('pagebeforeshow', function (e) {

     $(this).find('#form').on('submit', function () {
        var q = $(this).find('#input').val();
        localStorage.setItem("key", q);
        return true;
    });

    lastSearchString = localStorage.getItem("key");
    $(this).find('#input').val(lastSearchString);        
});
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:42:03+00:00Added an answer on June 12, 2026 at 7:42 am

    Your requirement to load from local storage and store on the page needs to be done by binding to the pagebeforeshow event (look at the section “Page transition events”) and not the pageinit event like you are currently doing.

    $('.pageClassSelector').on('pagebeforeshow', function (e) {
        // load from localStorage ...
        $('.q').val(lastSearchString);
    });
    

    Furthermore generally each page element (where you have data-role=’page’) should have a unique ID so you can use that instead of the CSS selector.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to bind this submit event from a form which not always
In jQuery-Mobile I'm submitting a form programmatically and I want to capture the submit
Referring to the plugin: http://malsup.com/jquery/form/#getting-started I've recently tried to upgrade from old v2.28 to
<button type=button value=click me onclick=check_me(); /> function check_me() { //event.preventDefault(); var hello = document.myForm.username.value;
I wrote a jquery plugin for validating forms. It bounds itself to the $('element').Submit
On my page I'm using a form which on submit should get some extra
I tried to write a jquery form check code, if value is empty /
tried uncommenting pam_limits.so from the pam.d directory but no luck. Basic PAM seems to
Tried to create a mobile navigation using dataview or outline and the view renders
Tried to search for this online and didn't get very far, so I'm asking

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.