SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    disable select boxes

    Hi,
    I use the below code to loop through all the availble select on my page to ensure at least 1 is <> to select, what I need to do now is when one is selected disable all the other selects. How can I do this.

    Code:
    function checkme()
    {
      var error = 0;
      var ok = 0;
      var error_message = "You need to choose at least one transfer.";
     
       
    var allselects= document.getElementsByTagName('select');
    var L= allselects.length;
    for(var i=0;i<L;i++)
    {
    var tem= allselects[i];
    var temname= tem.name;
    var temIndex= tem.selectedIndex;
    var temValue= tem.options[temIndex].value;
    
        if (temValue == 'Select')
    	{
          	error = 0;
        }
    	else
    	{
    		ok = 1;
    		
    	}
    }
    
    
    
    if (ok == 1) { 
    	return true;
        
      } else {  
    	 alert(error_message);
        return false; 
      } 
    }
    Thanks
    Chris

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Chris,

    This will disable all selects which do not have the option selected with value = 'Select':
    Code:
    function disableSelects()
    {
      var i, v, a = document.getElementsByTagName('select');
      for (i = 0; i < a.length; ++i) {
        v = a[i].options[a[i].selectedIndex].value;
        if (v != 'Select') {
          a[i].disabled = true;
        }
      }
    }
    I don't really understand the rest of your question. By "<>" I assume you mean "not equal"?

  3. #3
    SitePoint Addict
    Join Date
    Mar 2005
    Posts
    274
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster View Post
    Hi Chris,

    This will disable all selects which do not have the option selected with value = 'Select':
    Code:
    function disableSelects()
    {
      var i, v, a = document.getElementsByTagName('select');
      for (i = 0; i < a.length; ++i) {
        v = a[i].options[a[i].selectedIndex].value;
        if (v != 'Select') {
          a[i].disabled = true;
        }
      }
    }


    I don't really understand the rest of your question. By "<>" I assume you mean "not equal"?
    Thanks for replying,
    This is what I want to do, I have a random amount of selectboxes that I need to check at least 1 is some thing other than select! and disable all other boxes and if I change it back to select it re-enables the others!

    Is that clearer.

    Chris

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No that is not clearer, in fact you contradicted what you said in the first post.

    Can you give us a link to the page? or post the html for the selects?


Bookmarks

Posting Permissions

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