By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,620 Members | 1,303 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,620 IT Pros & Developers. It's quick & easy.

reset hidden variable after posting the form

P: 14
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.

Expand|Select|Wrap|Line Numbers
  1.         <html>
  2.         <head>
  3.             <?php
  4.             if(trim($_POST['name1']) == 'yes') {
  5.                 header("Content-type: application/vnd-ms-excel");
  6.                 header("Content-Disposition: attachment; filename=$filename.xls");
  7.             }else {
  8.                 ?>
  9.         </head>
  10.         <body onload="tempFn()">
  12.             <script language="javascript" type="text/javascript">
  13.                 function tempFn(){  
  14.                     global_search.name1.value = "";
  15.                 }
  16.                 function gs_download2xl_c() {
  17.                     document.getElementById('name1').value="yes";
  18.                     document.global_search.submit();
  19.                 }
  20.             </script>
  21.             <form name="global_search" id="global_search" action="test_1.php" method="POST">
  22.                 <input type="text" id="name1" name="name1" />
  23.                 <a  class="underline"  style="cursor: pointer" onclick="gs_download2xl_c();">
  24.                     Download2excel
  25.                 </a>
  26.             </form>
  27.                 <?php } ?>
  28.         </body>
  29.     </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.
Jan 3 '11 #1
Share this Question
Share on Google+
1 Reply

P: 607
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.reset() in ur code document.global_search.rese() or place this code before the </body> tag

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. document.global_search.reset();
  3. </script>
  4. </body>
This will do when u r reloading the same page.

Thanks and Regards
Ramanan Kalirajan
Jan 4 '11 #2

Post your reply

Sign in to post your reply or Sign up for a free account.