Javascript does not work

Hi

my javascript works in IE but not in Firefox. I would really appreciate so help with this!! this is my code :


 <script for="window" event="onload">
      query();
    </script>
    
    <script>
      function query() {
        var vacancyRows = vacanciesTable.tBodies[0].rows;
        var count = vacancyRows.length - 1;           
      
        var query = location.search;
        
      //-- If there isn't a query --//
        if(query == "" || query == "?category=&location=&skills=") {
        
        //-- Do nothing! --//
        }
        
      //-- Else --//
        else {
          query = query.substr(1);
          var queryParts = query.split("&");
          
          for(var i = 0; i < queryParts.length; i++) {
          
            var nameAndValue = queryParts[i].split("=");
            var name = nameAndValue[0];
            var value = nameAndValue[1].replace("/\\+/g", " ");
            for(var rowIndex = 1; rowIndex < vacancyRows.length; rowIndex++) {
            
              var curRow = vacancyRows[rowIndex];
              if(curRow.style.display == "none") continue;
              
              switch(name) {
              
                case "category" :{

                //-- Put value in category select --//
                  searchForm.categorySelect.value = value;
                
                //-- Hide rows that don't match this category --//
                  if(curRow.cells[1].innerText.indexOf(value) == -1) {
                  
                    curRow.style.display = "none";
                    count--;
                  }
                  
                  break; 
                }
                
                case "location" :{
                
                //-- Put value in location Select --//
                  searchForm.locationSelect.value = value;
                
                //-- Hide rows that don't match this location --//
                  if(curRow.cells[6].innerText.indexOf(value) == -1) {
                  
                    curRow.style.display = "none";
                    count--;
                  }
                
                  break;
                }
                
                case "skills" :{
                
                //-- Put value in skills input --//
                  searchForm.skillsInput.value = value;
                    
                //-- Hide rows that don't match these skills --//
                  if(curRow.innerText.toLowerCase().indexOf(value.toLowerCase()) == -1) {
                  
                    curRow.style.display = "none";
                    count--;
                  }
                
                  break;
                }
              }
            }
          }
          
          vacanciesTable.style.display = "block";
          
          messageDiv.style.display = "block";
          if(count == 0) nomatchesElem.style.display = "block";
          else matchesElem.style.display = "block";
        }
      }
    </script>

thanx

Jeff666

Try replacing
<script for=“window” event=“onload”>
query
</script>

onload=query;

added to the other script should work in IE and others.

Hi mrhoo

Thanks very much for your reply, it works a treat :slight_smile: :slight_smile: :). You are a life saver!!

Jeff666

Hi

My Javascript is working in everything but not firefox, strange

Jeff666

Try putting window.onload = query; at the bottom of the script. Or better, just put the script at the bottom of the body, just before the closing </body> tag. Then you don’t need to faff about with any onload stuff.

Hi

I did as you said I have put the script into a seperate js file as an inlcude
say it still doesn’t work
but it does in IE

Jeff666

Does Firefox show <tbody> tags in view-source?

I’ve been trying to help Jeff with this and there is no tbody in the source in firefox or IE

The reason I asked was because I saw this:
var vacancyRows = vacanciesTable.tBodies[0].rows;

IE “adds” tbody tags to the rendered mark-up if they’re not in the source mark-up, but Firefox doesn’t.

The HTML DOM is supposed to contain the tbody elements whether they are in the source or not. It is only XHTML where they need to be in the source to be in the DOM.

So it is just that IE view source displays the source as generated from the DOM while Firefox displays the original source that produces that difference in view source. What the JavaScript sees will be the same in both cases though.

By using Firebug in firefox i can see that there are table tbody’s.

I don’t know loads about javascript but i know a little. Shouldn’t there be the document.getElementByID for the table tbody?

It just seems strange that this code works in IE but not in firefox and i can’t see any reason for it not working

Looking at page in Ie and firefox, the description column should be hidden but it’s not if firefox

Does it work in Opera, Safari and Chrome?

Just tried in Chrome and it doesn’t work