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 5 of 5
  1. #1
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts

    Can you void and null an ID in a form?

    I have a script that validates all elements in the form. It makes sure all Inputs have some kind of content

    Code:
    function validate_form ( )
    {
        var valid = true;
        var f = document.erod; 
     for( var i=0; i < f.elements.length; ++i)
     {
      if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title") 
    
      {
            alert ( "Please fill in the necassary box." );
            f.elements[i].style.color="#ff0000";
            valid = false;
      }
     }
        return valid;
    }
    What i need is for it to not even check a section. It has about 10 radio buttons and its not necassary to fill this out.

    The ID inside the form that i need overlooked is "where_seen"

    If you need my HTML then let me know.

    Thanks for any help in the right direction.

  • #2
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    What if you just appended another if statement in? or something similar
    Code:
    function validate_form ( )
    {
        var valid = true;
        var f = document.erod; 
     for( var i=0; i < f.elements.length; ++i)
     {
      if(!f.elements[i].id == 'where_seen')
      {
        if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title") 
    
        {
              alert ( "Please fill in the necassary box." );
              f.elements[i].style.color="#ff0000";
              valid = false;
        }
      }
     }
        return valid;
    }

  • #3
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    well, i was able to make a work around, but i was hoping there was an easier way to di it rather than this way. I just made the validation not include the radio buttons and the input in that ID

    Code:
    function validate_form ( )
    {
        var valid = true;
        var f = document.erod; 
     for( var i=0; i < f.elements.length; ++i)
     {
      if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title" && f.elements[i].type != "radio" && f.elements[i].name != "tv_text") 
    
      {
            alert ( "Please fill in the necassary box." );
            f.elements[i].style.color="#ff20000";
            valid = false;
      }
     }
        return valid;
    }
    is there an easier way?

    EDIT** haha ninnypants thats what i came up with, is there an easier way?

  • #4
    Regular Coder ninnypants's Avatar
    Join Date
    Apr 2008
    Location
    Utah
    Posts
    504
    Thanks
    10
    Thanked 47 Times in 47 Posts
    Quote Originally Posted by jcdevelopment View Post
    well, i was able to make a work around, but i was hoping there was an easier way to di it rather than this way. I just made the validation not include the radio buttons and the input in that ID

    Code:
    function validate_form ( )
    {
        var valid = true;
        var f = document.erod; 
     for( var i=0; i < f.elements.length; ++i)
     {
      if( String(f.elements[i].type).toLowerCase()=="text" && f.elements[i].value=="" && f.elements[i].name != "nom_title" && f.elements[i].type != "radio" && f.elements[i].name != "tv_text") 
    
      {
            alert ( "Please fill in the necassary box." );
            f.elements[i].style.color="#ff20000";
            valid = false;
      }
     }
        return valid;
    }
    is there an easier way?

    EDIT** haha ninnypants thats what i came up with, is there an easier way?
    Only what you did here as far as I know.

  • Users who have thanked ninnypants for this post:

    jcdevelopment (08-05-2008)

  • #5
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    ok, well it works.. i suppose it will do. thanks!


  •  

    Posting Permissions

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