Tuesday, May 10, 2022

[FIXED] How can I pass text from <a> to textarea on another page?

Issue

What I want is pretty much the most basic Add product to enquiries you can get.

On my product page there will be a button add to enquiries.

Now how can I pass just that product name when clicking on the add to enquries button to the enquiries page. That name must then be entered into a textarea field.

I would prefer to do this using Javascript or JQuery if I can.

Any help would be greatly appreciated.


Solution

You can use localstorage for this. For example, in the product page, when the button is clicked, you can store it in localstorage as:

function addToEnquiries(){
let productName= document.getElementById("productName").value;
localStorage.setItem("product",productName);
}

Then on page load of the Enquiries page, you can retrieve it as:

function onPageLoad(){
console.log("Product name is ",localStorage.getItem("product"));
}


Answered By - codingsplash
Answer Checked By - Pedro (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.