0

I want to copy this input from page A and paste to page B

Let say this is Page A :

<input type="text" class="Name" id="cName" Value="Hey" readonly/>
    <input type="number" class="Qty" id="cQty" Value="1" readonly/>
        <input type="text" class="Price" id="cPrice" Value="10" readonly/><button class="" id="copy">Copy/?Add to Page B?</button>

This is Page B:

<ol><button class="" id="add">Add</button>
                    <li>
            <input type="text" class="Name" id="pName" Value="" readonly/>
    <input type="number" class="Qty" id="pQty" Value="" />
                <input type="text" class="Price" id="pPrice" Value="" readonly/><button class="" id="cancel">Cancel</button>
                </li><input type="text" class="Name" id="" Value="" readonly/>
    <input type="number" class="Qty" id="tQty" Value="Total Quantity" readonly/>
                <input type="text" class="Price" id="tPrice" Value="Total Price" readonly/></ol>

I read that I can't copy and paste, so is there another way of it? like adding Page A input text straight to Page B input text, like "add to shopping carts?"

Thanks for all the expert here.

user3322550
  • 3
  • 1
  • 7

2 Answers2

1

If you have no option to use server-side programming, such as PHP, you could use the query string, or GET parameters.

In the form, add a method="GET" attribute:

<form action="b.html" method="GET">
    <input type="text" name="serialNumber" />
    <input type="submit" value="Submit" />
</form>

When they submit this form, the user will be directed to an address which includes the serialNumber (for example) value as a parameter. Something like:

http://www.example.com/display.html?serialNumber=XYZ

You should then be able to parse the query string - which will contain the serialNumber parameter value - from JavaScript, using the window.location.search value:

// from b.html
document.getElementById("write").innerHTML = window.location.search; // you will have to parse
                                                                     // the query string to extract the
                                                                     // parameter you need

See also JavaScript query string.

The alternative is to store the values in cookies when the form is submit and read them out of the cookies again once the b.html page loads.

See also How to use JavaScript to fill a form on another page.

Community
  • 1
  • 1
Deniss Baronov
  • 122
  • 1
  • 9
0

You can take this value either by form post method or use browser cookies and very easy to implement.

And the methods varies as per your programming language.

Sushil Kandola
  • 870
  • 2
  • 9
  • 22