Jump to content
  • Advertisement
Sign in to follow this  
Brainx7

Problem with input validation

This topic is 1573 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

function for validation 

$(document).ready(function() {
    $('#btnSubmit').click(function(e) {
        var isValid = true;
         var isValid2 = true;
        $('input[type="text"].required').each(function() {
            if ($.trim($(this).val()) == '') {
                isValid = false;
                $(this).css({
                    "border": "1px solid red",
                    "background": "pink"
                });
            }
            else {
                $(this).css({
                    "border": "",
                    "background": ""
                });
            }          
        });
               $('textarea.required').each(function() {
            if ($.trim($(this).val()) == '') {
                isValid2 = false;
                $(this).css({
                    "border": "1px solid red",
                    "background": "white"
                });
            }
            else {
                $(this).css({
                    "border": "",
                    "background": ""
                });
            }
        });
        
        
        
        if (isValid == false || isValid2 == false  || document.getElementsByName('management')[0].value == 'select' ||  document.getElementsByName('management2')[0].value == 'select' )
          
       {     e.preventDefault();
            alert('Complete form first');  
       
             document.forms["myForm"]["management"].style.borderColor = " red";  
            document.forms["myForm"]["management2"].style.borderColor = "red";  
       
       
       }       
    });
});

 

function for show/hide

 

     $(document).ready(function() {
   $('.select').change(function() {
        var textarea = $('#textarea');
        var select = $('.select').val();

        textarea.hide();
        console.log(select);
        if (select == 'Will') {
            textarea.show();
        
            
              
        }
        if (select == 'Will not') {
            
          
            
            textarea.hide().empty();
            
 
            
        }
         
          
        
    });   

});

 

so I have    <select class=" select select_class  "   name="management" >
    <option value="select"  selected=" "  >Select One</option>
    <option value="Will"   >Will</option>
    <option value="Will not"  >Will Not</option>   </div>   
</select>

<textarea id="textarea"   name="searching_gig_des" wrap="VIRTUAL" cols="50" rows="5"     ></textarea>

 

 

When you choose "will" a text area will appear, when you choose" will not" the textarea will hide so my problem is that if its hidden the input validation will still work for the text area, because is just hidden not removed, so if anybody could help me on making the condition for the validation to work when the text area is shown only that would be great.

Edited by Brainx7

Share this post


Link to post
Share on other sites
Advertisement

I've figured it out

 

I have this in the show/hide now

 

     if (select == 'Will') {
            textarea.show().addClass("required");
        
            
              
        }
        if (select == 'Will not') {
            
          
            
            textarea.hide().empty().removeClass("required");
            
 
            
        }

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!