简体   繁体   中英

jQuery mobile - What is the best way save user input?

I have an HTML page with a user form and text fields that get initial values (from a php program on a server). The user can modify these fields.

One of the fields is a link button for search suppliers

<a href="supplier_search.html?id=123" data-role="button" id="quotesuppname" data-icon="arrow-r" data-iconpos="right" rel="external">Supplier</a>

When the user clicks to modify supplier name, he/she gets prompt to a new page with a list of suppliers from db. I want to get user input from this page and return to the previous page or another page. To display the latest user input on that original page and change fields according to input from other pages.

In HTML I would usually send query strings back and forward to preserve user input. I don't want to do it here because I want to keep supplier search independent.

What is the best way to keep User input on a certain page and to retrieve it whenever I want using JS or jQuery(without slowing down performance)?

Page1(User Input) ->Page2(userinput)-> Page1(display original user input and modify it accordinaly to page2)

OR

Page1(User Input) ->Page2(userinput)-> Page3(userInput)-Page1(display original user input and modify it accordinaly to page2 and page3 input)

Thanks for your help

I recommend using LocalStorage or placing the value(s) in JavaScript variables. To set a variable in localstorage, all you have to do is this:

var test = "hello world";
localstorage.storageTest = test; 

You can then retrieve that value by doing this:

var test2 = localstorage.storageTest;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM