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 9 of 9
  1. #1
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Mandatory Form Fields

    I want to set the fields of my form as mandatory. I am using the following script. But it doesn't work.

    How should I edit it?

    Thanks.

    ---


    <form
    action="http://us.geocities.yahoo.com/forms?login=abc"
    method="post">
    <input type="hidden" name="address"
    value="newsletter@abc.com"><input
    type="hidden" name="Subject"
    value="Newsletter Subscription"><input
    type="hidden" name="next_url"
    value="http://www.abc.com/nlconf.html"><input
    type="hidden" name="mandatory"
    value="name city email agree"><input
    type="hidden" name="errorpage"
    value="nlformerror.html"><table border="0"
    width="510">...

  • #2
    Regular Coder
    Join Date
    Feb 2003
    Location
    California
    Posts
    925
    Thanks
    0
    Thanked 0 Times in 0 Posts
    when doing the submit, you could put the direction based on the field input, if there isn't anything then throw and alert that says the field is missing, so basically check to see if all the values aren't null or empty.


    Jason

  • #3
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I have just 4 fields so one alert will do it all.

    but my problem is:

    even when you submit it totally empty, it goes on to say thank you.

    I want it to go to the error page instead.

  • #4
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ehhh could u perhaps either.

    1. post ur entire code.
    2. post the link to ur code.


    I assume there must be some java script in the part of code u didn't post since there is none in the posted code

  • #5
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Here it is:

    <form
    action="http://us.geocities.yahoo.com/forms?login=fiscalstudy"
    method="post">
    <input type="hidden" name="address"
    value="newsletter@fiscalstudy.com"><input
    type="hidden" name="Subject"
    value="Newsletter Subscription"><input
    type="hidden" name="next_url"
    value="http://www.fiscalstudy.com/nlconf.html"><input
    type="hidden" name="mandatory"
    value="name city email agree"><input
    type="hidden" name="errorpage"
    value="nlformerror.html"><table border="0"
    width="510">
    <tr>
    <td><table border="0" cellpadding="2"
    cellspacing="0" width="500">
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>Name:</b></font></td>
    <td><input type="text"
    size="30" name="Name"></td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>City:</b></font></td>
    <td><input type="text"
    size="30" name="City"> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>State/Country:</b></font></td>
    <td><input type="text"
    size="30"
    name="State/Country"> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>E-mail:</b></font></td>
    <td><input type="text"
    size="30" name="Email"> </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    <td align="right"><p
    align="left"><font
    face="Trebuchet MS"><input
    type="checkbox" name="agree"
    value="yes"> By clicking
    &quot;Subscribe&quot;, I
    agree to the </font><a
    href="javascriptpenup2('http://www.fiscalstudy.com/nlterms.html','nlterms')"
    onmouseover="this.style.color='red'"
    onmouseout="this.style.color='black'"><font
    face="Trebuchet MS">Terms of
    Use</font></a><font
    face="Trebuchet MS"> of the
    newsletter.</font></p>
    </td>
    </tr>
    <tr>
    <td>&nbsp;</td>
    </tr>
    <tr>
    <td align="right"><input
    type="submit"
    value="Subscribe"></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>

  • #6
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And here is your answer. this code won't let u submit the form if any field is left empty.


    Code:
    <html>
    <head>
    <script>
      function validate()
    	{ 
    	  for(i=0;i<document.form1.elements.length;i++)
    	  { 
      	  if(document.form1.elements[i].value=="")
    			{
    			  alert('Fill Out all fields');
    			  return false;
    			}
    		}
    		document.form1.submit();
    	}
    </script>
    </head>
    <body>
    <form name="form1"
    action="http://us.geocities.yahoo.com/forms?login=fiscalstudy"
    method="post">
    <input type="hidden" name="address"
    value="newsletter@fiscalstudy.com"><input
    type="hidden" name="Subject"
    value="Newsletter Subscription"><input
    type="hidden" name="next_url"
    value="http://www.fiscalstudy.com/nlconf.html"><input
    type="hidden" name="mandatory"
    value="name city email agree"><input
    type="hidden" name="errorpage"
    value="nlformerror.html"><table border="0"
    width="510">
    <tr>
    <td><table border="0" cellpadding="2"
    cellspacing="0" width="500">
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>Name:</b></font></td>
    <td><input type="text"
    size="30" name="Name"></td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>City:</b></font></td>
    <td><input type="text"
    size="30" name="City"> </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>State/Country:</b></font></td>
    <td><input type="text"
    size="30"
    name="State/Country"> </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td align="right"><font
    size="2"
    face="Verdana,Geneva"><b>E-mail:</b></font></td>
    <td><input type="text"
    size="30" name="Email"> </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td> </td>
    <td align="right"><p
    align="left"><font
    face="Trebuchet MS"><input
    type="checkbox" name="agree"
    value="yes"> By clicking
    "Subscribe", I
    agree to the </font><a
    href="javascriptpenup2('http://www.fiscalstudy.com/nlterms.html','nlterms')"
    onmouseover="this.style.color='red'"
    onmouseout="this.style.color='black'"><font
    face="Trebuchet MS">Terms of
    Use</font></a><font
    face="Trebuchet MS"> of the
    newsletter.</font></p>
    </td>
    </tr>
    <tr>
    <td> </td>
    </tr>
    <tr>
    <td align="right"><input type="Button"
    value="Subscribe" onclick="validate();"></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  • #7
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Great!

    Thanks a lot! (It doesn't work with the tick box tough)

    ----

    So, I won't need an error page with this script, right?
    Last edited by ssskaya; 06-06-2003 at 11:09 PM.

  • #8
    Regular Coder
    Join Date
    Jul 2002
    Posts
    698
    Thanks
    0
    Thanked 0 Times in 0 Posts
    put this instead of the function you had.
    -with it you have to check the checkbox.
    -u can put an attribute on the fields called 'faultDescription'
    exemple: <input type="checkbox" name="agree" value="yes" faultDescription="You have to agree to the terms, to subscribe">
    it gives a more saying faultdescription

    Code:
    function validate()
    { 
    	for(i=0;i<document.form1.elements.length;i++)
    	{
    		if(document.form1.elements[i].type.toLowerCase()=='checkbox')
    		{  
    			if(document.form1.elements[i].checked==false)
    			{
    				if(document.form1.elements[i].faultDescription=="")
    				{                             
    					alert('Fill Out all fields');
    					return false;
    				}
    				else
    				{
    					alert(document.form1.elements[i].faultDescription); 
    					return false;
    				}
    			}
    		}
    		else
    		{
    			if(document.form1.elements[i].value=="")
    			{
    				if(document.form1.elements[i].faultDescription=="")
    				{                             
    					alert('Fill Out all fields');
    					return false;
    				}
    				else
    				{
    					alert(document.form1.elements[i].faultDescription); 
    					return false;
    				}		
    			}
    		}
    	}
    	document.form1.submit();
    }

  • #9
    Regular Coder
    Join Date
    Oct 2002
    Location
    USA
    Posts
    255
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks again!

    This is even a better script.

    It worked all fine.


  •  

    Posting Permissions

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