0

An invoice will be opened in a new window when the Generate invoice button is clicked.

Below is the sample code. For Example

    <form name="invoice" action="inv_rec.php" method="post" id="inv" target="invoices" onsubmit="return check_counter();" >
    <table>
    <tr>
       <td>
          <label for="cusname"><strong>Customer Name*&nbsp;</strong></label>
          <input type="text" size="20" name ="cusname" value="" id="Customername"     required/>
       </td>
       <td>
           <label for="for_place"><strong>Place</strong></label>
           <input type="text" size="20" name ="for_place" value=""  id="for_place" />
       </td>
    </tr>
    ........
    <tr>
        <td>
            <input type="submit" value="Generate Invoice" name="submit" id="sub">
        </td>
     </tr>
  </table> 
</form>

<script>
var counter = 1;
function check_counter()
{
 if(counter == 1)
{
 alert("Please enter the product details");
 return false;
}
 window.open('', 'invoices', 'width=650,height=800,status=yes,resizable=yes,scrollbars=yes');

return true;
}
</script>

In my example the page will be redirected to inv_rec.php(opens in new window) which contains dynamically generated data obtained from mysql where the user needs to take the print of it. I want to clear all the form data which is open in the previous window(where the invoice form is displayed,i.e user fills the data to generate a invoice).

4 Answers 4

2

Redirect the page after form is submitted.

header('location:redirect.php');

or unset the variables in form

In Jquery:

$('#form_id')[0].reset();

Sign up to request clarification or add additional context in comments.

1 Comment

I Cant redirect the page as the user needs to take the print of the invoice that will be opened in new tab.My concern is to automatically clear all the form data entered during invoice generation when the "Generate invoice" button is clicked.
0

You can use either javascript or jquery to achive this

In javascript

document.getElementByName("invoice").reset();

In jquery

$("#formId").reset();

Add id to your form to use this

<form name="invoice" id="invoice" action="generate_invoice.php" method="post" target="_blank">

1 Comment

Thanks for the swift reply Deepu.I tried it before posting the issue,it did not work for me.Actually in the code after submit the generated invoice will be opened in new tab.My concern is to clear all the form data entered during invoice generation when the "Generate invoice" button is clicked.
0

Due to the fact that someone could just disable javascript and still POST your form, I don't think it'd be a safe bet to rely on JS to do your cleaning for you.

I'd recommend looking into the post/redirect/get pattern.

Comments

0

You question is not too clear? are you clearing the form fields so that it is ready for another fresh set of inputs? if so, you can make the call to reset just before you call the window.open() method in your java script; something like this:

<script>
var counter = 1;
function check_counter()
{
 if(counter == 1)
   {
      alert("Please enter the product details");
       return false;
    }
  $('#formid).reset();  //assuming you are using jquery
 window.open('', 'invoices','width=650,height=800,status=yes,resizable=yes,scrollbars=yes');

return true;
}
</script>

4 Comments

Thanks for the swift response johnson.Yes I want to clear the form fields so that it is ready for another fresh set of inputs.I tried with it but it didnt workout and i am using jquery.
What did you use in #formid? you are meant to replace that with the id of the form. looking again at your code i see that your formid is inv. so do this...`$('#inv').reset()'. if it doesnt work trying using firefox and check the error console for the complaint...rgds
I placed the same code that is `$('#inv').reset() before window.open in code. It didnt work and there are no errors reported in firebug console in firefox browser.
i mean firefox built in error console...use CRTL+SHIFT+J shortcut to open it...if it contains too many info, clear it and reload ur page and call it up again. it will give you a clue of which javascript call is misbehaving

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.