75 users online (0 members and 75 guests)  




Page 1 of 2 12 Last
  Results 1 to 10 of 18
Digg button stumble

Related

  1. HTML Form with required fields    Forum: HTML Forum
    Replies: 10
  2. Required Form Fields    Forum: Javascript Forum
    Replies: 1
  3. Replies: 1
  4. Replies: 3
  1. #1
    san's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2002
    Posts
    4

    required fields in a form

    Hello,

    I'd like to know how to make certain text entry fields in a form mandatory. I can't seem to find the code anywhere.

    Thanks alot.
    San



  • #2
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    you could use this (if you have PHP enabled):

    PHP Code:
    <?php
    if ($form1 && $form2 && $form3) {
    echo 
    "Thank you for submitting your form";
    } else {
    echo 
    "You have not filled out all the required fields. Place hit your back button and fill out all the required fields.";
    }
    ?>
    or you could use javascript:

    Code:
    <script language="javascript">
    <!--
    var form1 = formname.inputname.value
    if (form1==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    }
    var form2 = formname.inputname2.value
    if (form2==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    }
    var form3 = formname.inputname3.value
    if (form3==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    }
    -->
    </script>
    I think that javascript one shoudl work but I just wrote that up so maybe it won't, check it out though.

  • #3
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    *fix*

    Code:
    <script language="javascript">
    <!--
    var form1 = formname.inputname1.value
    var form2 = formname.inputname2.value
    var form3 = formname.inputname3.value
    if (form1==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    }
    if (form2==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    }
    if (form3==""&&Submit=1) {
    alert("You have not filled out all the required fields.");
    } else {
    location.href="blah.html";
    }
    -->
    </script>

  • #4
    san's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2002
    Posts
    4

    Thumbs up

    whoa! that was quick. you guys rule. thanks!

  • #5
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    gee I love users who actually say thank you, a lot of them don't...

    your welcome

  • #6
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76
    i use a simple code for that. it's let's the CGI script do all the work. here's the HTML:

    <FORM METHOD=POST ACTION="cgi/bnbform.cgi">
    <INPUT TYPE="HIDDEN" NAME="required" VALUE="name,email,message">

    <INPUT TYPE="HIDDEN" NAME="data_order" VALUE="name,email,phone,subject,message">

    <INPUT TYPE="HIDDEN" NAME="submit_to" VALUE="contact@whatever.com">

    <INPUT TYPE="HIDDEN" NAME="form_id" VALUE="Contact from What Ever Dot Com">

    <INPUT TYPE="HIDDEN" NAME="ok_url" VALUE="http://www.whatever.com/thanks.htm">

    <INPUT TYPE="HIDDEN" NAME="not_ok_url" VALUE="http://www.whatever.com/oops.htm">

    you can find this CGI script at http://www.bignosebird.com hope that helps.
    robert koons

  • #7
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    actually that javascript checker didn't even work I just tested it cause I was bored and came up with a working one:

    Code:
    <html>
    
    <head>
    
    <script language="javascript">
    <!--
    function check() {
    if (document.daform.fname.value=="") {
    alert("You did not fill our your first name.");
    }
    if (document.daform.lname.value=="") {
    alert("You did not fill our your last name.");
    }
    if (document.daform.number.value=="") {
    alert("You did not fill our your number.");
    } else {
    location.href="blah2.html";
    }
    }
    -->
    </script>
    
    </head>
    
    <body>
    
    <form name="daform">
    First Name: <input type="text" size="15" name="fname">
    <br>
    Last Name: <input type="text" size="15" name="lname">
    <br>
    Number: <input type="text" size="15" name="number">
    <br>
    <input type="Button" value="Submit" name="Submit" onclick="check()">
    </form>
    
    </body>
    
    </html>

  • #8
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76
    what if you had an initial value set for the inputs. could you adjust the script to check for two options? like this maybe:

    <script language="javascript">
    <!--
    function check() {
    if (document.daform.fname.value=="enter your name here" "") {
    alert("You did not fill our your first name.");
    }
    if (document.daform.lname.value=="") {
    alert("You did not fill our your last name.");
    }
    if (document.daform.number.value=="") {
    alert("You did not fill our your number.");
    } else {
    location.href="blah2.html";
    }
    }
    -->
    </script>

    </head>

    <body>

    <form name="daform">
    <input type="text" size="15" name="fname" value="enter your name here">
    etc....
    robert koons

  • #9
    Derek's Avatar
    Be Yourself

    Status
    Offline
    Join Date
    Aug 2001
    Location
    St. George, Utah, USA
    Posts
    466
    you mean just adding this:

    Code:
    <script language="javascript">
    <!--
    function check() {
    if (document.daform.fname.value=="Enter Your First Name") {
    alert("You did not fill our your first name.");
    }
    if (document.daform.lname.value=="Enter Your Last Name") {
    alert("You did not fill our your last name.");
    }
    if (document.daform.number.value=="Enter Your Number") {
    alert("You did not fill our your number.");
    } else {
    location.href="blah2.html";
    }
    }
    -->
    </script>
    if this is what you want, yes, this would work.

  • #10
    pegboy's Avatar
    Senior Member

    Status
    Offline
    Join Date
    Aug 2001
    Location
    Knoxville, TN
    Posts
    76
    but will that still work if the field is empty?


    robert koons

  • Page 1 of 2 12 Last

    Tags for this Thread

    Posting Permissions

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