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


- Joined: Sep 02, 2010
- Posts: 2
- Status: Offline
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:
here the body
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>
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>
- <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>
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å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>
<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å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>
- <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å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>
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
September 2nd, 2010, 5:07 am
- righteous_trespasser
- Scuffle


- Joined: Mar 12, 2007
- Posts: 6228
- Loc: South-Africa
- Status: Offline
- savagestudio
- Born


- Joined: Sep 02, 2010
- Posts: 2
- Status: Offline
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
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
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 3 posts
- Users browsing this forum: No registered users and 155 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
