Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2005
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Required fields and printing

    Hello, I have a form that I have a number of required fields either text boxes or check boxes that are required to be filled in before they can print it out and give it to someone else in the company. I have put a print button on the page so I was hopeing you could tell me two things:

    1. How do I make a feild required
    2. How to I make the print button check the required fields have all been filled before bringing up the print box?

    <input type="button" value="Print" onClick="window.print();" tabindex="50">

    Thanks in advance.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Code:
    <script type="text/javascript">function validate(oFrm){
      if (oFrm.theTextField.value == ""){ //textbox
         alert("Required!");
         oFrm.theTextField.focus();
         return false;
      }
      if (!oFrm.theCheckboxField.checked){ //checkbox
         alert("Required!");
         oFrm.theCheckboxField.focus();
         return false;
      }
      //...do the same with other required fields
    
      return true; //all inputs are valid here
    }
    </script>
    ...
    <input type="button" value="Print" onclick="if (validate(this.form)) window.print();" tabindex="50" />
    But no validation will be performed if the user uses the browser's menu (File->Print) to print the page.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •