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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post

    onfocus/onblur with <select> tag

    greetings,

    i have a function that sets the onfocus and onblur event for every item in a table which then tells it to the change the class name. for some reason this doesn't seem to be working with the <select> inputs. i have heard it has something to do with how the option list re-loads itself???

    Code:
      function setTableActivation(){
    	  tableDiv = document.getElementById("tables");
    	  tables = tableDiv.getElementsByTagName("table");
    	  count = tables.length;
    	  for(var h=0;h<count;h++){
    		var table = tables[h];
    		table.accessKey = h;		
    		table.onfocus = function(){tables[this.accessKey].className = "activeTable";};
    		table.onblur =  function(){tables[this.accessKey].className = "searchreal";};	
    	  	for(var i=0;i<table.rows.length;i++){  	
    		  	row = table.rows[i]; 
    		  	row.accessKey = h;		
    		  	row.onfocus = function(){tables[this.accessKey].className = "activeTable";};
    		  	row.onblur =  function(){tables[this.accessKey].className = "searchreal";};	
    		  for(var j=0;j<table.rows[i].cells.length;j++){
    			  cell = table.rows[i].cells[j];
    			  cell.accessKey = h;
    			  cell.onfocus = function(){tables[this.accessKey].className = "activeTable";};
    			  cell.onblur =  function(){tables[this.accessKey].className = "searchreal";};	         
    				  for (var k = 0; k < cell.childNodes.length; k++) {
    					    if (cell.childNodes[k].nodeType == document.ELEMENT_NODE) {
    					    	cell.childNodes[k].accessKey = h;
    					    	cell.childNodes[k].onfocus = function(){tables[this.accessKey].className = "activeTable";}; 
    						  	cell.childNodes[k].onblur = function(){tables[this.accessKey].className = "searchreal";}; 	
    						  	if(cell.childNodes[k].tagName == "SELECT"){
    						  		 
    						  }
    						  		
    				              }
    				}		  
    	                          }
    		  }
    	   }
    }

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,603
    Thanks
    0
    Thanked 645 Times in 635 Posts
    You need to use onchange with selects instead of onblur as the field doesn't lose focus when you set the value
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Mar 2012
    Posts
    13
    Thanks
    0
    Thanked 1 Time in 1 Post
    yeah i know i can do that but my problem then is how to check for when the user clicks something else. i don't care what the value of it is


  •  

    Posting Permissions

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