0

I am having one html page for recommendation. In this page I have different buttons like choose contact, choose merchant. In choose merchant button, I have one textbox, after clicking on the button I will navigate to the page which contains the list of merchants. After clicking on merchant name, that merchant name should displayed in textbox of recommend.html (first html page), but its not possible as the textbox id belongs to different html page and that merchant name id belongs to different html page. I m able to append that merchant name to the same html page of choose merchant but can't append it to the recommend.html..anybody knows solution for this,..?

3
  • 1
    A Fiddle / code examples would be great. Commented Apr 23, 2014 at 6:00
  • 2
    You need to use some server side code. Try using sessions to maintain the state of page. You can also use cookies if you want to do this only through javascript. Commented Apr 23, 2014 at 6:01
  • 1
    To spin ahead on what @AbhasTandon said, check out: github.com/carhartl/jquery-cookie Commented Apr 23, 2014 at 6:02

3 Answers 3

1

In a simple code example, using HTML5's session storage,

On your merchant list page, before bouncing back to the recommendation page, set the session storage item when the merchant is selected:

sessionStorage.setItem("selectedMerchant", "merchant_name");

On the recommendation page, read the item and display recommendations based on the selected merchant name:

var selectedMerchant = "";
if ( sessionStorage.getItem("selectedMerchant") ) {
    selectedMerchant = sessionStorage.getItem("selectedMerchant");
}

Of course, you will need to handle various conditions, such as clearing the selected merchant names and validating the values, etc.

Check out the link below for more references:

https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage

Sign up to request clarification or add additional context in comments.

5 Comments

can u please chcek my code and tell me where i m wrong..before it was working but dont know what changes i have made..now its not working..after selecting merchant list..i wrote
Did you post your online somewhere?
here is the link pls check it and tell me where i m doing wrong stackoverflow.com/questions/23243341/…
I see there are other folks already provided answered on the question. Best luck!
@kyo..still not getting output..by your code only..i tried and it was working but now its not going to work..pls tell me where i m wrong in the code.
0

You need to generate that html code and have to pass it in that page using jquery For example if that element is like "#merchant" and generated html is like $("") then append it to selected element using insertAfter or appendTo

Comments

0

When you click on second.html (where ever merchant name exists), you need to submit a html form with action attribute to recommend.html and pass the merchant name as a hidden input type .

Then from second.html, you can access the POST parameters and display it in your text box.

Basically you need to have some server side coding (JSP/PHP/PERL etc)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.