I have javascript working on IE but not on FF, are there things I should look for inparticular?

Inparticular that is not working is the "onclick function" I call.

Thanks, Regards X

Recommended Answers

All 12 Replies

Can we have some code from you

There is alot of code in short:

// Javascript
function load(image) {
 switch(image) {
  case 1:
   company.innerHTML="COMPANY";
   screenshot.src="screenshot.jpg";
   screenshot.alt="SCREENSHOT";
   url.href="http://www.comapny.com";
   url.innerHTML="COMPANY WEBSITE";
   line.innerHTML="Company is Blah Blah Blah";
   break;
 }
}

//HTML
<h1 id="company"></h1>
<img onclick="load(1)" id="screenshot" />
<a href id="url"></a>
<p id="line"></p>

You'll need to specify both method's with your elements to make it work in IE and firefox.
Here's a short example

//The getElementById Method handles all modern browser -
// while the document.all goes with IE mode browser.

var company = (( document.getElementById ) ? document.getElementById("company") : document.all["company"] );

Switch( image ) {
case1 : company.innerHtml = "COMPANY"; break;
// So on....
}

So 'essential' in short that line of code will be interupted by all modern browsers and IE to retrieve the HTML id "company", which will then allow alterations to be preformed?

I attempted this and it still dosent work. Any ideas?

Should I be using a different variable name to id name eg. company > company?

Thankyou, Regards X

Definitely it will be thrown by the modern browser, especially in firefox, chrome, konqueror, etc.

So you must apply those methods mentioned above, if you want to make it cross-platform.

Just let us know if you still need anything.
Good day...

Ya sorry I was in the process of editing it.

I attempted this and it still dosent work. Any ideas?

Should I be using a different variable name to id name eg. company > company?

You have to use getElementById() not only for company but all the other HTML element you are using in the code like: screenshot, url and line.
And You do not have to use different name from id's of HTML elements.

Try this, it's your modified script.

<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
<!--
// Keeping all the basic so that you can easily interpret all code lines..

// Defining Global Variables
var $load;
var $company, $screenshot, $line, $url;

// Creating function
$load = function( $image ) {

   $company = (( document.getElementById ) ? document.getElementById("company") : document.all["company"] ); // First Level Heading <h1>

  $screenshot = (( document.getElementById ) ? document.getElementById("screenshot") : document.images["screenshot"] ); // Goes to your image <img>

   $url = (( document.getElementById ) ? document.getElementById("url") : document.all["url"] ); // goes to you anchor <a>

   $line = (( document.getElementById ) ? document.getElementById("line") : document.all["line"] ); // paragraph <p>


// Switch statement
   switch( $image ) {
   case 0 : alert( false ); break;
   case 1 : {    
   $company.innerHTML = "COMPANY";
   $screenshot.src = "screenshot.jpg";
   $screenshot.alt = "SCREEN";
   $url.href = "http://www.company.com/";
   $url.innerHTML = "COMPANY WEBSITE";
   $line.innerHTML = "Company blah blah blah";
break; 
   }
   default : $screenshot.src = ""; break; 
   } 
};
//-->
</script>
</head>
<body>
<h1 id="company"></h1>
<img src="./image1.png" id="screenshot" onclick="$load( 1 );" alt="test image" />
<a href="#" id="url">Testing absolute path</a>
<p id="line"></p>
</body>
</html>
commented: Great coding example! Thankyou! +3

I will attempt that now, but should we be using $ for variables and functions in javascript I thought that was only for php?

I've put up a $ sign next to your variables to skip you out of any trouble that it might cause you, Since your load variable, is also a referred as a javascript properties used to load XML(e.g. xmlDoc.load("myXml.xml"); //Loading XML Document document for DOM Manipulation.

A $dollar sign is considered as a legal identifier in javascript, so using it with your variables is not an issue...

It's been tested 99.9%

Ya I tested your page then applied the logic worked perfectly.

Thankyou very much, helped alot.

On a side note so can I reference all my variables with a $ in javascript without recieving any syntax issues (as it is easier to differiant).

Thanks

Yeah you can referenced all your variables starting with a $ sign.

Same as you were using prototype.js frameworks.

If you need some detailed information regarding about javascript variables, Check out this link

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.