Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript not working in Internet Explorer 1

Status
Not open for further replies.

marflo500

IS-IT--Management
May 16, 2007
36
DM
Hello Everyone,

I have some Javascript that will not run in IE. It works OK in Firefox however. The code is supposed to toggle between hiding and displaying a few form elements when you click on a link. At first I thought it was because of the way IE treats the "getElementById" function (which I used in my code) but I commented out all the code and used the "alert" function to simply display a pop-up message and as before it worked in Firefox but not in IE. So far I have done the following to no avail:

1) Ensured that active scripting was enabled in the security settings of IE
2) Disabled pop-up blocking
3) Tried accessing the site from a machine with no antivirus/security software
4) Tried IE7 and IE6

I am out of ideas so any help would be appreciated. Here is an excerpt of the code

Code:
<?php defined('_JEXEC') or die('Restricted access'); ?>
<script type="text/javascript">

function changeVisibility()
{
  if (document.getElementById("MySearchPhrase").style.display=="table-row")
  {
    document.getElementById("MySearchPhrase").style.display="none";  
  }
  else
  {
    document.getElementById("MySearchPhrase").style.display="table-row";
  }
  
  if (document.getElementById("MyOrdering").style.display=="table-row")
  {
    document.getElementById("MyOrdering").style.display="none";  
  }
  else
  {
    document.getElementById("MyOrdering").style.display="table-row";
  }
  
   if (document.getElementById("MySearchOnly").style.display=="table-row")
  {
    document.getElementById("MySearchOnly").style.display="none";  
  }
  else
  {
    document.getElementById("MySearchOnly").style.display="table-row";
  }
}
</script>

<!--//there is HTML code here but it is not relevant to the problem-->

<label for="Advanced" style="cursor:pointer">Advanced</label>
				<input type="hidden" id="Advanced" onclick="changeVisibility()" />

Thanks in advance
Liam
 
Hi

Liam said:
I have some Javascript that will not run in IE.
Does nothing ? Does something else then expected ? Throws error ?

As far as I know, Explorer 6 does not know all [tt]table[/tt]-related [tt]display[/tt] types. This may include '[tt]table-row[/tt]' too. As debugging, try to use '[tt]block[/tt]' instead.

Feherke.
 
Sorry for not being clearer. When I click on the link nothing happens. No errors at all. Just nothing. At first I thought it was an error in the code but I tried a simple alert and it did not run in IE either. This suggests to me that IE is just not executing the JavaScript.

I tried "block" and "inline" but that did not do anything. IE just won;t execute the JAvaScript no matter what the code is.

Liam
 
Neither IE nor Opera fire the JS. If you want them to, you should move the onclick from the hidden field to the label.

Personally, I'd not expect it to work in the browsers it does, as you are never really clicking (and could never click) on the hidden field (the clue is in the name!).

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks BillyRayPreachersSon,

That did the trick.

Liam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top