简体   繁体   中英

How to convert html content to ms word after I entered value in input text?

I am trying to convert html content to Microsoft word (.doc) after I entered value, I had done how to converting html content to ms word but when I entered the value in input text, the entered text is not displaying on the ms word. it only display the default content of the html file.

Please help me with this, I need it badly for my thesis thank you. here is my code:

<form method="post">
    <input type="button" value="Add Row" onclick="addRow('dataTable')">
    <input type="button" value="Delete Row" onclick="deleteRow('dataTable')">
    <table id="dataTable" name="table1" width="350px" border="1">
        <tr>
            <td><p>table value 1</p></td>
            <td><p>table value 2</p></td>
        </tr>
    </table>
    <div align="center">
        <input type="text" name = "text" id = "text" align="center"/></br>
        <input type="button" id = "back" value="Back" class="button" align = "center" />
        <input type="submit" id = "login" name="submit" value="Save" class="button" />
    </div>
</form>

here is my javascript code for converting html to ms word:

<script type="text/javascript">
        $(document).ready(function(){
            $("form").submit(function(){
                <?php
                if(isset($_POST['submit'])){
                header("Content-Type: application/vnd.ms-word"); 
                header("Expires: 0"); 
                header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
                header("content-disposition: attachment;filename=test.doc");
                }
                ?>
            });
        });
</script>

you are actually mixing php with jquery here.. what you can do is.. send the content from the form to a file example. info_save.php where you can keep your php code:

            <?php
            if(isset($_POST['submit'])){
            $name = $_POST['name'];
           // try saving the $name to the file using sme class library
            header("Content-Type: application/vnd.ms-word"); 
            header("Expires: 0"); 
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
            header("content-disposition: attachment;filename=test.doc");
            }
            ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM