PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 10, 2022

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

 May 10, 2022     forms, html, javascript, jquery, product     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home
View mobile version

0 Comments:

Post a Comment

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

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing