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

Thread: Form Validation

  1. #1
    New to the CF scene
    Join Date
    Aug 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form Validation

    I have never used JavaScript before. Is it possible to check to see if another box on the form has any entry in it before making it mandatory to fill out the rest of the form? Like if the person enters an item, then they would have to fill out the description box on the form, but only if there was an entry made in the item box. I know that you can check to make sure that a box is filled in, but I want to tie two boxes together.

  • #2
    Smokes a Lot
    Join Date
    Jul 2003
    Location
    CA, USA
    Posts
    1,594
    Thanks
    5
    Thanked 20 Times in 20 Posts
    Quite possible. . . .

    Somthing like this?

    Code:
    <html>
    <head>
    <style type="text/css">
    .opt
    {
    	background-color:#c2c2c2;
    }
    </style>
    <script type="text/javascript">
    
    function writeFields()
    {
    	var f1=document.getElementById('field1');
    	var f2=document.getElementById('field2');
    	var f3=document.getElementById('field3');
    	if(f1.value!="")
    	{
    		f2.onfocus="";
    		f3.onfocus="";
    		f2.style.background="#FFF";
    		f3.style.background="#FFF";
    	}
    }
    </script>
    </head>
    <body>
    <form>
    	<input type="text" onblur="writeFields()" id="field1">
    	<input type="text" class="opt" onfocus="this.blur();" id="field2">
    	<input type="text" class="opt" onfocus="this.blur();"id="field3">
    </body>
    </html>
    Basscyst
    Helping to build a bigger box. - Adam Matthews


  •  

    Posting Permissions

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