Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Javascript works for showing hidden on IE but not FF/Safari

Posted on 2008-10-02
11
Medium Priority
?
306 Views
Last Modified: 2008-10-03
I have some code that runs great on IE but not at all on FF.  Any help would be greatly appreciated...

<table>
<tr id="bTextRow" style="display:none">
<td>  data

This hides fine but...

if(showOption == '')
{      
document.getElementById("bTextRow").style.display = "none";
document.getElementById("bTextRow").style.display = "hidden";
}
else
{
document.getElementById("bTextRow").style.display = "";
document.getElementById("bTextRow").style.visibility = "visible";
}

Doesnt do anytyhing except on IE. I have had this problem before and never really figured it out.  On IE the TR shows fine on all other browsers nothing happens.

Any help would be greatly appreciated.
0
Comment
Question by:CLupo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 3

Expert Comment

by:jcparedes
ID: 22628041
I've used this function to hide/show a whole <div>. It works just fine in both IE and firefox. Just wrap all the html code you want to hide inside a div. Something like this

<div id="MailFromDiv" name="MailFromDiv" style="display:none;">
[your html code]
</div>

and you call it like this:

javascript:toggle('MailFromDiv')

Cheers
function toggle(id) {  
  var state = document.getElementById(id).style.display;  
  if (state == 'block') {  
    document.getElementById(id).style.display = 'none';  
  }
  else {  
    document.getElementById(id).style.display = 'block';  
  }  
} 

Open in new window

0
 
LVL 1

Author Comment

by:CLupo
ID: 22628092
That didnt work at all for me - the TR isnt hidden that i put inside the div.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22628176
I have just tested your code and it works for me on FF and  Chrome.
So my assumption is that you have elsewhere problems.
Do you click on a link?
Can we see the page?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:CLupo
ID: 22628236
I can allow you access yes...

http://adbuilderpro.mediagistic.com/
username: experts
password: exchange

once logged in go to:
http://adbuilderpro.mediagistic.com/index.cfm?sector=AdBuilderPro&page=home&action=customize&TempID=683&catID=294&groupID=12

Under the picture of the mowers you can click select.  That is what triggers the action to show the "pricing options" you will see.  This pricing option will not show under FF or Safari.
0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22628689
Your link shows like this:
<A class=TxtGeneralSmallNoPad id=sHREF_2692 onclick=setClass(this); href="javascript:parent.setSelectedImage('Product1', 2692);">SELECT</A>
 
That link generates this error message:
Fehler: sProductID is null
Quelldatei: http://adbuilderpro.mediagistic.com/index.cfm?sector=AdBuilderPro&page=home&action=customize&TempID=683&catID=294&groupID=12#
Zeile: 809
 
And this is the source:
		function setSelectedImage(groupindex, imageid)
			{
				var foundindex = -1;
				for(var i=0; i<myarray.length; i++){
					if(myarray[i] != null){
						if(myarray[i].length > 0){
							if(myarray[i][0] == imageid){
								foundindex = i;
								break;
							}
						}
					}
				}
				if(foundindex != -1){
					var mydiv = document.getElementById('productdiv_' + groupindex);
					var newInner = "";
					for(var i=0; i<myarray[foundindex].length; i++)
						{
							if(showArray[i] == 1)
								newInner += displayArray[i] + ":  " + myarray[foundindex][i] + "<BR>";
							
							var thisFormField = document.getElementById(groupindex + '_' + dbArray[i]);
							if(thisFormField)
								{
									thisFormField.value = myarray[foundindex][i];
								}
						}
					mydiv.innerHTML = newInner; 
					mydiv.style.display = 'block';
					var formTrick = document.getElementById('Dixon_Blackbear_3417_open_2c_' + groupindex);
					formTrick.value = 'dd296710-50d9-4527-8590-73893a25b34d';
					var sProductID = document.getElementById('Dixon_Blackbear_3417_open_2c_' + groupindex + '_selectedID');
					sProductID.value = imageid; //<<< this line
					burstSet('Product1','none');
				}
			}
 
And the reason why you get no Object with that ID is that you do NOT have ids!
Look here:
<input type="hidden" name="Dixon_Blackbear_3417_open_2c_Product1_selectedID" id="" >
 
The problem is that IE takes name= same as id=
And FF does NOT take name for ID.

Open in new window

0
 
LVL 1

Author Comment

by:CLupo
ID: 22628700
That is not the same code that is something completely different.
0
 
LVL 1

Author Comment

by:CLupo
ID: 22628708
I am just trying to find out why the show doesnt work.
0
 
LVL 63

Accepted Solution

by:
Zvonko earned 2000 total points
ID: 22628982
Here is the element that is fetched in IE by Name (and cannot be fected in FF by id=):

<INPUT id="" type=hidden value=2692 name=Dixon_Blackbear_3417_open_2c_Product1_selectedID>

After that failed Object access are following two statements skipped:
                              sProductID.value = imageid;
                              burstSet('Product1','none');

And the second one is never executed:
            function burstSet(groupindex,showOption)
                  {
                        var prodcutDiv = document.getElementById('productdiv_' + groupindex);
                        var burstTextRow = document.getElementById('bTextRow');
                        
                        if(showOption == '')
                              {      
                                    document.getElementById("bTextRow").style.display = "none";
                                    document.getElementById("bTextRow").style.display = "hidden";
                              }
                        else
                              {
                                    document.getElementById("bTextRow").style.display = "";
                                    document.getElementById("bTextRow").style.visibility = "visible";
                              }
                  }
0
 
LVL 1

Author Comment

by:CLupo
ID: 22629049
I am so sorry I didnt understasnd that the first time you posted it - you are a real life saver thanks!
0
 
LVL 1

Expert Comment

by:zivperry
ID: 22629148
Table's elements are not box elements so, you can not use display:block to handle the display state. You have to use the table display properties:
table, table-row, table-cell.....etc.


In order to show/hide table element (for example table row - tr) use the following code:


function toggleTableRow(rowId) {
	var tr = document.getElementById(rowId);
	tr.style.display = (tr.style.display == 'none') ? 'table-row' : 'none';
}

Open in new window

0
 
LVL 63

Expert Comment

by:Zvonko
ID: 22632061
You are welcome.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question