Thread: Form checks

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7

    Form checks


    Hi,

    Am a noobie seeking help here.
    the script below is for a contact form. As is, it only requires the textarea value to be filled out. i would like to add to it so that the name value (<input type="text" name="name" value="">) and subject value (<input type="text" name="subject" value="">) are also required.

    Can anyone help? Much thanks in advance!

    Code:
    <script language="javascript">
    function checkForm(obj){
      if(obj.checkMailCntIfNull.value == 'true'){
        var temp = obj.mailContent.value;
        if(temp == null || temp == ''){
          alert("<?php echo $txt["must_enter_content"] ?>");
          return false;
        }
      }
      return true;
    }
    </script>
    Last edited by eropsy; March 27th, 2013 at 06:18 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    74
    Rep Power
    18
    Are you using HTML5? If so, you can use the 'required' attribute.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7
    Originally Posted by Aurum84
    Are you using HTML5? If so, you can use the 'required' attribute.
    I thought about switching to HTML5....but I figured the shortest route would be to just add a piece of coding to what I already have...

    Guess, I will have to switch to HTML5!

    thanks for your reply
  6. #4
  7. CSS & JS/DOM Adept
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jul 2004
    Location
    USA (verifiably)
    Posts
    20,124
    Rep Power
    4303
    Why don't you give modifying the script you posted a try?

    These might help a little:
    http://www.quirksmode.org/js/forms.html
    http://jibbering.com/faq/notes/form-access/
    http://www.javascriptkit.com/javatutors/form6.shtml
    http://www.javascriptkit.com/javatutors/valid3.shtml

    Originally Posted by Aurum84
    Are you using HTML5? If so, you can use the 'required' attribute.
    Versions of IE before 10 do not support that attribute.
    Spreading knowledge, one newbie at a time.

    Check out my blog. | Learn CSS. | PHP includes | X/HTML Validator | CSS validator | Common CSS Mistakes | Common JS Mistakes

    Remember people spend most of their time on other people's sites (so don't violate web design conventions).
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    51
    Rep Power
    7
    Originally Posted by Kravvitz
    Why don't you give modifying the script you posted a try?

    These might help a little:
    http://www.quirksmode.org/js/forms.html
    http://jibbering.com/faq/notes/form-access/
    http://www.javascriptkit.com/javatutors/form6.shtml
    http://www.javascriptkit.com/javatutors/valid3.shtml


    Versions of IE before 10 do not support that attribute.
    I did it like below, and so far it works with IE 7...

    Code:
    <!--[if lt IE 9]><script type="text/javascript" src="js/html5.js"></script><![endif]-->
    Last edited by eropsy; March 28th, 2013 at 01:31 PM.

IMN logo majestic logo threadwatch logo seochat tools logo