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.

2
  • 1
    If you're moving data from one page to another, you should ideally be posting the data back to the server and processing it that way, rather than trying to do this client side. Commented Feb 20, 2014 at 9:26
  • hmm so sry, but how do i do that? using php file? Commented Feb 20, 2014 at 12:34

2 Answers 2

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.

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

1 Comment

I kind of get it. but what do i write in b.html? I can't seems to get the outcome in b.html
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.

5 Comments

Ohh dear, I am not a tutor! Try goggling and make your concepts strong that how form post and cookies works. Which programming language you are following?
programming language? i'm still googling. most just show how to submit but not how to show on page b
php, asp or java etc? which language you are using?
Follow tutorials, Post Method : w3schools.com/PHP/php_forms.asp and Cookies : w3schools.com/php/php_cookies.asp
No need to say thanks here. Can vote-up the answer :).

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.