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

    object.style isnt working

    I was trying to change the style of a dropdown menu when a user misses it.

    So basically when they submit and the user misses a dropdown i need it to have a "red" border, if possible.

    For now i just made the style a large width.. it wont work though. what am i doing wrong?

    Code:
    if (formObj.name.value == "null"){
    formObj.name.focus();
    alert('Please select an option for Name');
    return false;
    document.getElementById("name").style.width="200px";
    }
    return true;
    }

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    I was trying to change the style of a dropdown menu when a user misses it.

    So basically when they submit and the user misses a dropdown i need it to have a "red" border, if possible.

    For now i just made the style a large width.. it wont work though. what am i doing wrong?

    Code:
    if (formObj.name.value == "null"){
    formObj.name.focus();
    alert('Please select an option for Name');
    return false;
    document.getElementById("name").style.width="200px";
    }
    return true;
    }
    blue line is never executed because of return false:
    Code:
    if (formObj.name.value == "null"){
       formObj.name.focus();
       alert('Please select an option for Name');
       return false;
       document.getElementById("name").style.width="200px";
     }
     return true;
    }
    best regards

  • #3
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    so is there a way around this? Or possibly a way to rewrite this?

  • #4
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    so is there a way around this? Or possibly a way to rewrite this?
    move return false after document.getElement...
    Code:
    if (formObj.name.value == "null"){
    formObj.name.focus();
    alert('Please select an option for Name');
    document.getElementById("name").style.width="200px";
    return false;
    }
    return true;
    }
    I don't know if that is what you want to do but in this case set focus and resize element will be both executed.

    best regards

  • #5
    Senior Coder jcdevelopment's Avatar
    Join Date
    Oct 2007
    Location
    Cowboy Nation
    Posts
    2,182
    Thanks
    174
    Thanked 257 Times in 257 Posts
    See, i tried in the first place, but for some reason it will submit the form. Am i doing something wrong with this.. let me give you the whole code..

    Code:
    <script language="javascript">
    
    function fCheck(formObj){
    //alert(formObj.name.value);
    if (formObj.name.value == "null"){
    formObj.name.focus();
    alert('Please select an option for Name');
    document.getElementById("name").style.backgroundColor="#ff0000";
    return false;
    
    }
    
    if (formObj.address.value == "null"){
    formObj.address.focus();
    alert('Please select an option for Address 1');
    return false;
    }
    if (formObj.city.value == "null"){
    formObj.city.focus();
    alert('Please select an option for City');
    return false;
    }
    if (formObj.state.value == "null"){
    formObj.state.focus();
    alert('Please select an option for State');
    return false;
    }
    if (formObj.zip.value == "null"){
    formObj.zip.focus();
    alert('Please select an option for Zip');
    return false;
    }
    return true;
    }
    </script>

  • #6
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by jcdevelopment View Post
    See, i tried in the first place, but for some reason it will submit the form. Am i doing something wrong with this.. let me give you the whole code..

    Code:
    <script language="javascript">
    
    function fCheck(formObj){
    //alert(formObj.name.value);
    if (formObj.name.value == "null"){
    formObj.name.focus();
    alert('Please select an option for Name');
    document.getElementById("name").style.backgroundColor="#ff0000";
    return false;
    
    }
    
    if (formObj.address.value == "null"){
    formObj.address.focus();
    alert('Please select an option for Address 1');
    return false;
    }
    if (formObj.city.value == "null"){
    formObj.city.focus();
    alert('Please select an option for City');
    return false;
    }
    if (formObj.state.value == "null"){
    formObj.state.focus();
    alert('Please select an option for State');
    return false;
    }
    if (formObj.zip.value == "null"){
    formObj.zip.focus();
    alert('Please select an option for Zip');
    return false;
    }
    return true;
    }
    </script>
    that means formObj.xxxx.value is never null. I would check first formObj to see if is undefined and then test each formObj.xxx.value. For some form elements is possible formObj.xxx to don't have a value for example, I'm not sure, but select don't have.

    best regards

  • Users who have thanked oesxyl for this post:

    jcdevelopment (01-28-2009)


  •  

    Posting Permissions

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