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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Standards

Status
Not open for further replies.

cmackowski

IS-IT--Management
Jun 23, 2000
20
US
Hello All,
First I have no real knowledge of javascripts. Only examples that I have been able to find.
We have an intranet site which is unable to work with Firefox. I am assuming that the problem is MS JVM scripts vs. Sun Javascript. This site needs overhaul for other reasons. Personally Opinion that the offending tags should be changed since Firefox is one of our supported browsers.
First question:
Is there a utility which will look at code for each page and correct problems? Is there something that can translate from JVM to Sun Javascript?
Can anyone give me some ideas what is going on with the following examples: -- I found these in Firefox javascript console. -- Any Help is greatly appreciated!!

**Warning: Non-standard document.all property was used. Use W3C standard document.getElementById() instead.
Source File: Line: 20


function fnSrvJump(){
window.location.href = "namesearch.asp?name="+document.all.srvJump.value;
}
function fnSrvJumpShow(){
window.title2.style.display = "block";
document.all.btnJump.focus;
}


**Error: obj has no properties
Source File: Line: 11
**Error: obj has no properties
Source File: Line: 15


function fnShowRows(obj, pic)
{
var str = pic.src;
var lenVal = str.lastIndexOf("/");
if (str.substr(lenVal) == "/expand.gif"){
obj.style.display = "block";
pic.src = "images/collapse.gif";
}
else{
obj.style.display = "none";
pic.src = "images/expand.gif";
}
}

**Error: window.event has no properties
Source File: Line: 47


function mouseHover(state)
{
var row = window.event.srcElement;
row.style.cursor='hand';
if (state == "over")
{
var colorChange = "#000000";
}
else
{
var colorChange = "#FFFFFF";
}
row.style.color = colorChange;
}

**Error: window.navigate is not a function
Source File: Line: 43


}
function fnSelect(sPage)
{
window.navigate('Reports/'+sPage);
}
 
Is there a utility which will look at code for each page and correct problems? Is there something that can translate from JVM to Sun Javascript?
I don't know of anything that would validate JS in this way...but the Firefox JS console is a good place to start.

IE's implements JS differently to Firefox, which means that their isn't necessarily a function which works for all...you have to program JS specifically for cross-platform compatibility.

Take for example, event handling.
Code:
fooObject = document.getElementById('foo');
fooObject.onclick = barFunc;

function barFunc(e) {
  [COLOR=green]// eventObj is an object representing the event itself[/color]
  eventObj = (e)?e:event;
  [COLOR=green]// Standards browsers pass the event Object as a function variable.  IE uses event as a global.[/color]

  [COLOR=green]//elementObj is the element which triggered the event[/color]
  elementObj = (eventObj.srcElement)?eventObj.srcElement:eventObj.target;
  [COLOR=green]// srcElement is Microsoft's way of referring to the originating element.  target is the Standards way of referring to the originating element.[/color]
The code above is cross-platform: the ternary operator accounts for the browser differences.

<marc>
New to Tek-Tips? Get better answers - faq581-3339
 
cmackowski said:
I am assuming that the problem is MS JVM scripts vs. Sun Javascript ... Is there something that can translate from JVM to Sun Javascript?

You appear to be mixing your terminologies without knowing about those terminologies. JVM is Java Virtual Machine, and as any developer will tell you, Java is a VERY, VERY different technology from JavaScript.

cmackowski said:
Is there a utility which will look at code for each page and correct problems?

If we assume that the problem is a simple JS or DOM incompatibility, or sloppy / non-standard coding, then the JavaScript console in Firefox is your best friend. Open it up, and look at some of the error messages - then try and resolve them one by one.

manarth said:
IE's implements JS differently to Firefox

I wouldn't agree entirely with this. They implement JS in much the same way... it's just that IE is more open about how you access certain elements in the DOM (or rather, Firefox is less loose, and forces you to use correct standards to do so).


As I said, use the Firefox console, and look at each of the errors in turn - half the time, they tell you what to do. Take this example:

cmackowski said:
**Warning: Non-standard document.all property was used. Use W3C standard document.getElementById() instead.

window.location.href = "namesearch.asp?name="+document.all.srvJump.value;

This means that "document.all" is not standard, and you should convert it to "document.getElementById()" instead. It's a pretty clear error message, I'd say.

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
And following on from that, here is how you might resolve the first error you mentioned, by using the suggestion in the console in FF:
Code:
function fnSrvJump(){
    window.location.href = "namesearch.asp?name="+[b]document.getElementById('[/b]srvJump[b]')[/b].value;
}

Do a global find over your intranet source files for document.all and address them all using the technique above. If you wanted to be really safe, you might test for the presence of the element before you attempt to access it's value parameter.

Code:
function fnSrvJump(){
    [b]if (document.getElementById('srvJump'))[/b]
        window.location.href = "namesearch.asp?name="+document.getElementById('srvJump').value;
}

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]

What is Javascript? faq216-6094
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top