Javascript works in IE, Safari, Chrome, but not FF or Opera

  • savagestudio
  • Born
  • Born
  • savagestudio
  • Posts: 2

Post 3+ Months Ago

hello i have a probleme with a javascript that work on IE, safari,Chrome but doesn't in firefox or opera :

it is a simple script that erase and rewrite the content of 2 select list/menu from an 2 array.. I will apreciate some help on this one, here is the code that write the option of the select menu:
i will put all the script and highlight where is the problem:

Code: [ Select ]
<script language="javascript">//(arrays are empty for space)

var sub_cat_array = new Array(); //1st array for 2nd list
var sub_cat_array2 = new Array(); //2nd array for 3rd list

window.onload=function(){
document.getElementById("hidden_elements").style.display="none";
document.getElementById("hidden_elements2").style.display="none";
document.getElementById("markedslist").onchange=selcted;
document.getElementById("subcat1").onchange=selcted2;
  }
  
  function selcted(){
    document.getElementById("hidden_elements").style.display="none";//reset
    document.getElementById("hidden_elements2").style.display="none";//reset
    if(document.getElementById("markedslist").value !="all"){
    document.getElementById("hidden_elements").style.display="block";
    
    
    }else{  
    document.getElementById("hidden_elements").style.display="none";
    document.getElementById("hidden_elements2").style.display="none";
    }
    var markedslist=this.value;
    var sub_cat=document.getElementById("subcat1");  
    sub_cat.options.length=0;

//probleme start here
    
  ] for(var i=0;i< sub_cat_array.length; i++){
      var st = sub_cat_array[i][0];
      if(st==markedslist){
        var opt = new Option(sub_cat_array[i][1]);
      //  var val = sub_cat_array[i][2];
        opt.value=sub_cat_array[i][2];
        try{
          sub_cat.add(opt,opt.value);
          }catch(e){
            sub_cat.add(opt);
            }
        }
      
      }
    } // probleme finish here and it is the same for the function selcted2 below


  function selcted2(){
    if(document.getElementById("subcat1").value != "all"){
    document.getElementById("hidden_elements2").style.display="block";
    }else{  document.getElementById("hidden_elements2").style.display="none";
    }  
      var subcat1=this.value;
    var sub_cat2=document.getElementById("subcat2");  
    sub_cat2.options.length=0;
    
    for(var i=0;i< sub_cat_array2.length; i++){
      var st2 = sub_cat_array2[i][0];
      if(st2==subcat1){
        var opt2 = new Option(sub_cat_array2[i][1]);
        //var val2 = sub_cat_array2[i][2];
        opt2.value=sub_cat_array2[i][2];
        try{
          sub_cat2.add(opt2,opt2.value);
          }catch(e){
            sub_cat2.add(opt2);
            }
        }
      
      }
    }
</script>
  1. <script language="javascript">//(arrays are empty for space)
  2. var sub_cat_array = new Array(); //1st array for 2nd list
  3. var sub_cat_array2 = new Array(); //2nd array for 3rd list
  4. window.onload=function(){
  5. document.getElementById("hidden_elements").style.display="none";
  6. document.getElementById("hidden_elements2").style.display="none";
  7. document.getElementById("markedslist").onchange=selcted;
  8. document.getElementById("subcat1").onchange=selcted2;
  9.   }
  10.   
  11.   function selcted(){
  12.     document.getElementById("hidden_elements").style.display="none";//reset
  13.     document.getElementById("hidden_elements2").style.display="none";//reset
  14.     if(document.getElementById("markedslist").value !="all"){
  15.     document.getElementById("hidden_elements").style.display="block";
  16.     
  17.     
  18.     }else{  
  19.     document.getElementById("hidden_elements").style.display="none";
  20.     document.getElementById("hidden_elements2").style.display="none";
  21.     }
  22.     var markedslist=this.value;
  23.     var sub_cat=document.getElementById("subcat1");  
  24.     sub_cat.options.length=0;
  25. //probleme start here
  26.     
  27.   ] for(var i=0;i< sub_cat_array.length; i++){
  28.       var st = sub_cat_array[i][0];
  29.       if(st==markedslist){
  30.         var opt = new Option(sub_cat_array[i][1]);
  31.       //  var val = sub_cat_array[i][2];
  32.         opt.value=sub_cat_array[i][2];
  33.         try{
  34.           sub_cat.add(opt,opt.value);
  35.           }catch(e){
  36.             sub_cat.add(opt);
  37.             }
  38.         }
  39.       
  40.       }
  41.     } // probleme finish here and it is the same for the function selcted2 below
  42.   function selcted2(){
  43.     if(document.getElementById("subcat1").value != "all"){
  44.     document.getElementById("hidden_elements2").style.display="block";
  45.     }else{  document.getElementById("hidden_elements2").style.display="none";
  46.     }  
  47.       var subcat1=this.value;
  48.     var sub_cat2=document.getElementById("subcat2");  
  49.     sub_cat2.options.length=0;
  50.     
  51.     for(var i=0;i< sub_cat_array2.length; i++){
  52.       var st2 = sub_cat_array2[i][0];
  53.       if(st2==subcat1){
  54.         var opt2 = new Option(sub_cat_array2[i][1]);
  55.         //var val2 = sub_cat_array2[i][2];
  56.         opt2.value=sub_cat_array2[i][2];
  57.         try{
  58.           sub_cat2.add(opt2,opt2.value);
  59.           }catch(e){
  60.             sub_cat2.add(opt2);
  61.             }
  62.         }
  63.       
  64.       }
  65.     }
  66. </script>

here the body


Code: [ Select ]
<form id="form1" name="form1" method="post" action="">

<table width="778" border="0" id="markedsearch" cellpadding="0" cellspacing="5">
<tr>
  <td width="70" rowspan="2" align="center" valign="top" bgcolor="#000000" ><img src="<?php echo HTTP_SERVER;?>images/sok.jpg" width="70" height="50" /></td>
  <td width="200" align="left" ><select name="groupe1" class="listSize" id="markedslist">
   <option style="color:blue" value="all">Alle rubrikker</option>
   <option value="ein">Eiendom</option>
   <option value="bil">Bill</option>
   <option value="boa">B&aring;t</option>
   <option value="job">Jobb</option>
   <option value="tor">Torget</option>
  </select></td>
  <td width="172" align="left" > <div id="hidden_elements"><select class="listSize" name="groupe3" size="1" id="subcat1">
  </select> </div> </td>
  <td width="172" align="left" ><div id="hidden_elements2"><select class="listSize" name="groupe2" size="1" id="subcat2">
  </select></div></td>
  <td width="142" rowspan="2" align="center" valign="middle" ><input type="submit" name="submitmarked" id="submitmarked" class="submitmarked" value="Søk" /></td>
  </tr>
<tr align="left">
   <td colspan="3" align="center" valign="middle"><input name="criteria" class="searchimput_marked" type="text" id="criteria" size="60" />     </td>
  </tr>

</table>
</form>
  1. <form id="form1" name="form1" method="post" action="">
  2. <table width="778" border="0" id="markedsearch" cellpadding="0" cellspacing="5">
  3. <tr>
  4.   <td width="70" rowspan="2" align="center" valign="top" bgcolor="#000000" ><img src="<?php echo HTTP_SERVER;?>images/sok.jpg" width="70" height="50" /></td>
  5.   <td width="200" align="left" ><select name="groupe1" class="listSize" id="markedslist">
  6.    <option style="color:blue" value="all">Alle rubrikker</option>
  7.    <option value="ein">Eiendom</option>
  8.    <option value="bil">Bill</option>
  9.    <option value="boa">B&aring;t</option>
  10.    <option value="job">Jobb</option>
  11.    <option value="tor">Torget</option>
  12.   </select></td>
  13.   <td width="172" align="left" > <div id="hidden_elements"><select class="listSize" name="groupe3" size="1" id="subcat1">
  14.   </select> </div> </td>
  15.   <td width="172" align="left" ><div id="hidden_elements2"><select class="listSize" name="groupe2" size="1" id="subcat2">
  16.   </select></div></td>
  17.   <td width="142" rowspan="2" align="center" valign="middle" ><input type="submit" name="submitmarked" id="submitmarked" class="submitmarked" value="Søk" /></td>
  18.   </tr>
  19. <tr align="left">
  20.    <td colspan="3" align="center" valign="middle"><input name="criteria" class="searchimput_marked" type="text" id="criteria" size="60" />     </td>
  21.   </tr>
  22. </table>
  23. </form>
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • righteous_trespasser
  • Scuffle
  • Genius
  • User avatar
  • Posts: 6230
  • Loc: South-Africa

Post 3+ Months Ago

I don't see where you have hilighted the issue ... Anyhow, that is not the end of the world. I suggest you take a look at jQuery ... that could help you out a lot.
  • savagestudio
  • Born
  • Born
  • savagestudio
  • Posts: 2

Post 3+ Months Ago

Sorry for the Hiligth , the color didn't work inside the code tag ....i will look at Jquery thanks.... but the asnswer of my problem was that :

THIS:
try{
sub_cat2.options[sub_cat2.length] = new Option(sub_cat_array2[i][1],sub_cat_array2[i][2])
}catch(e){
sub_cat.add(opt,opt.value);

}

INSTEAD OF :

try{
sub_cat.add(opt,opt.value);
}catch(e){
sub_cat.add(opt);
}
FOR BOTH FUNCTION selcted() and selcted2()

THANKS FOR ANSWERING

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 94 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
cron
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.