www.webdeveloper.com
Results 1 to 3 of 3

Thread: javascript problem! with browser

  1. #1
    Join Date
    Sep 2010
    Posts
    3

    javascript problem! with browser

    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 :
    i have put all the script without the body part and have highlighted where is the problem:

    the think is that it work perfectly in other browser than firefox and opera and sea monkey...!


    Code:
    <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";
    document.getElementById("hidden_elements2").style.display="none";
    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;
    
    //PROBLEM 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]);;
                    opt.value=sub_cat_array[i][2];
                    try{
                        sub_cat.add(opt,opt.value);
                        }catch(e){
                            sub_cat.add(opt);
                            }
                    }
                
                }
            } 
    // FINISH HERE 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]);
                    opt2.value=sub_cat_array2[i][2];
                    try{
                        sub_cat2.add(opt2,opt2.value);
                        }catch(e){
                            sub_cat2.add(opt2);
                            }
                    }
                
                }
            }
    </script>

  2. #2
    Join Date
    Sep 2010
    Posts
    3

    here the body part if needed please help

    here the body part if needed
    It is a php file that is include in the main page so there is no headers..

    HTML Code:
    <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 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="subcat1" size="1" id="subcat1">
        </select>  </div>  </td>
        <td width="172" align="left" ><div id="hidden_elements2"><select class="listSize" name="subcat2" 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>

  3. #3
    Join Date
    Sep 2010
    Posts
    3

    Answered

    the answer is:

    Code:
     sub_cat.options[sub_cat.length] = new Option(sub_cat_array[i][1],sub_cat_array[i][2]);
    instead of:

    Code:
    sub_cat2.add(opt2,opt2.value);

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles