reset hidden variable after posting the form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • helplakshmi
    New Member
    • Dec 2009
    • 14

    reset hidden variable after posting the form

    I want to download the records of the output of search criteria to excel.
    As the fields for search criteria are more than 20. I am submitting the form with POST method rather than GET.

    On click of "Download2excel ", the hidden variable name1 is set to Yes. so i will check the condition in my code. Once the download is successful, I want to reset the variable.


    Here is a sample structure of my code.

    Code:
            <html>
            <head>
                <?php
                if(trim($_POST['name1']) == 'yes') {
                    header("Content-type: application/vnd-ms-excel");
                    header("Content-Disposition: attachment; filename=$filename.xls");
                }else {
                    ?>
            </head>
            <body onload="tempFn()">
        
                <script language="javascript" type="text/javascript">
                    function tempFn(){  
                        global_search.name1.value = "";
                    }
                    function gs_download2xl_c() {
                        document.getElementById('name1').value="yes";
                        document.global_search.submit();
                    }
                </script>
                <form name="global_search" id="global_search" action="test_1.php" method="POST">
                    <input type="text" id="name1" name="name1" />
                    <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
                        Download2excel
                    </a>
                </form>
                    <?php } ?>
            </body>
        </html>
    As i am not executing the form after posting the form, i am not able to access the variable name1 is in it. I want to reset the variable name1.

    I want to trigger the download, after submitting the form. As the records that are downloaded to excel should obey input search criteria.


    Please suggest me a better procedure.
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    On Submit are you reloading the same page or navigating to some other page? If you are reloading the same page means on body load use document.form.r eset() in ur code document.global _search.rese() or place this code before the </body> tag

    ex:
    Code:
    <script type="text/javascript">
    document.global_search.reset();
    </script>
    </body>
    This will do when u r reloading the same page.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    Working...