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 3 of 3

Thread: IF statements

  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    IF statements

    I am trying to find how to do the following:

    if Field 1 is completed

    then

    Field 2 must be filled out.


    I remember an online site that showed me, but I cant find it.

  • #2
    Regular Coder martin_narg's Avatar
    Join Date
    Jul 2002
    Location
    Chamonix, France
    Posts
    600
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Example:
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Form validation</title>
    <script type="text/javascript" language="javascript">
    function validate() {
    	var theForm = document.myForm;
    	
    	if(theForm.theFirstField.value.length > 1 && theForm.theSecondField.value.length == 0) {
    		alert("Please fill in the second field");
    		return false;
    	}
    	
    	alert("The form is ok to submit.");
    	return true;
    }
    </script>
    </head>
    
    <body>
    	<form name="myForm" method="post" action="?" onsubmit="return validate();">
    	
    		<p>First field:<br /><input type="text" name="theFirstField" /></p>
    		<p>Second field:<br /><input type="text" name="theSecondField" /></p>
    
    		<input type="submit" name="theSubmit" value="Submit" />
    	</form>
    </body>
    </html>
    Hope this helps.

    m_n
    "Cos it's strange isn't it. You stand in the middle of a library and go 'Aaaaaaaaaaaaaaaaggggggghhhhhhh!'
    and everybody just stares at you. But you do the same in an aeroplane, and everybody joins in."
    -Tommy Cooper

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Awesome Thank you!


  •  

    Posting Permissions

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