vendredi 27 août 2021

how to print a data from input fields to hard copy?

I am creating a project and want to print data that I put in input field on to hard copy ...

How can I do that?

for example: If I have a table with input fields and I will input data into the field using browser, now, as soon as I am done with input, I want to print that information. (CODE UNDER), I took this code from W3schools: When I press print button, it prints the webpage.. but it does not print the information that is given to it...

How can I do that>

Here my code:

<!DOCTYPE html>
<html>
<title>Print form</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<body>
<form method="post" action="" id="myfrm">
    <fieldset>
        <legend>Personal information:</legend>
        First name:<br>
        <input type="text" name="firstname">
        <br> Last name:<br>
        <input type="text" name="lastname">
        <br><br>
        <input type="submit" value="Submit">
    </fieldset>
</form>
<p align="center"><input type="button" onclick="myPrint('myfrm')" value="print"></p>
<script>
    function myPrint(myfrm) {
        var printdata = document.getElementById(myfrm);
        newwin = window.open("");
        newwin.document.write(printdata.outerHTML);
        newwin.print();
        newwin.close();
    }
</script>
</body>
</html>

'''




Aucun commentaire:

Enregistrer un commentaire