passing form data to another HTML page

tonga :

I have two HTML pages: form.html and display.html. In form.html, there is a form:

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

The form data is sent to display.html. I want to display and use the form data serialNumber in display.html, as shown below:

<body>
    <div id="write">
        <p>The serial number is: </p>
    </div>
    <script>
    function show() {
        document.getElementById("write").innerHTML = serialNumber;
    }
    </script>
</body>

So how can I pass the serialNumber variable from form.html to display.html so that the above code in display.html will show the serial number and the JavaScript function show() gets the serialNumber from the first HTML?

Richard JP Le Guen :

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="display.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 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 display.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 display.html page loads.

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Passing data to another page

Error passing php variables to another page via form data

Form data is passing in html table

Html form redirects to another page without inserting the data into database

Sending data from the form to an email with jQuery ajax and redirect to another page with passing POST variables not work

Is that possible to use the passing data form another page in Statefulwidget without using "widget."

Pass form data from one html page to another html page and datase in flask

Angular 2 Passing form data to another component

Pass data to another page and submit form on that page

Using <form> how would I pass data to another html page without opening the page

Passing select parameter along with the form data in html

Passing data from an html form into a Javascript object

HTML Form not passing data to php processor

Passing html data to a form inside bootstrap modal

Send data to another page - html

Passing Data from one form to another form in Yii2

Ionic page not passing data from transcript to HTML

Passing data into a React component from the HTML page?

Passing data from HTML page to PHP script

Passing Variable through JavaScript from one html page to another page

Django - passing data in another function to html

Passing 2 values from text form to another page through AJAX

How to redirect to another page with passing data after submitting form in using react-router-dom v6?

Displaying form input on another html page

submit should not redirect to another page in HTML form

Send Data one page to another page in HTML

Send form data to another page in JSON format

Posting form-data through another page

How to send data from form to another page?

TOP Ranking

HotTag

Archive