user3415421
user3415421

Reputation: 215

how to append the element by id from different html pages in javascript

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,..?

Upvotes: 0

Views: 128

Answers (3)

Kyo
Kyo

Reputation: 964

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

Upvotes: 1

Vinod Jayachandran
Vinod Jayachandran

Reputation: 3898

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)

Upvotes: 0

Sid
Sid

Reputation: 801

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

Upvotes: 0

Related Questions