...

View Full Version : Small JS Browser Problem



lavinpj1
12-28-2006, 02:29 AM
I have the following code:


function checkForErrors(server, port, username, password, password2, name, reference) {
var errorFields = '';
if (server != '<font color="green">OK</font>') {
errorFields = errorFields + "Database Server Address\n"
}
if (port != '<font color="green">OK</font>') {
errorFields = errorFields + "Database Server Port\n"
}
if (username != '<font color="green">OK</font>') {
errorFields = errorFields + "Database UserName\n"
}
if (password != '<font color="green">OK</font>') {
errorFields = errorFields + "Database Password\n"
}
if (password2 != '<font color="green">OK</font>') {
errorFields = errorFields + "Confirm Password\n"
}
if (name != '<font color="green">OK</font>') {
errorFields = errorFields + "Database Name\n"
}
if (reference != '<font color="green">OK</font>') {
errorFields = errorFields + "Your Reference Name\n"
}
if (errorFields.length != 0) {
alert("There were errors with: \n\n" + errorFields + "\nPlease correct them.")
}
else {
document.addDB.submit();
}
}

Which is called when you click a button:


<input type="button" name="butAdd" value="Add" onclick="checkForErrors(document.getElementById('txtServerOK').innerHTML, document.getElementById('txtPortOK').innerHTML, document.getElementById('txtUserOK').innerHTML, document.getElementById('txtP1OK').innerHTML, document.getElementById('txtP2OK').innerHTML, document.getElementById('txtNameOK').innerHTML, document.getElementById('txtOK').innerHTML)" />

This works fine in FireFox however Opera and IE tell me that every field has an error. Anyone know what's wrong here?

Thanks

~Phil~

lavinpj1
12-28-2006, 02:40 AM
Quick Update...

I have put the server variable in an alert to see that IE and Opera modify what I told to go in the controls...

It is supposed to be <font color="green">OK</font>

IE makes it <FONT color=green>OK</FONT>

and Opera makes it <FONT color="#008000">OK</FONT>

How can I make it... do what I told it to...?

Cheers

Phil

vegu
12-28-2006, 06:44 AM
Hi!

It would be a tad more efficient to pass some status variables instead of parsing strings. Somewhere you must be writing the <font color="green">OK</font> part ,no? Cant you have it set some variables to, like serverOkay = true, and pass those variables to the function?

If not , and youre only caring about the OK in the string you could check the strings this way



if (server.indexOf('OK') == -1) {
errorFields = errorFields + "Database Server Address\n"
}

Arbitrator
12-28-2006, 07:27 AM
The font element is deprecated so you shouldn’t be using it in the first place. If you use CSS to set the font color, you won’t have to test against that excess code nor will that excess code be in your XHTML source.

As for why your code is returned in uppercase, while that’s probably a bug, it’s probably explained by HTML element names being returned in uppercase. Opposingly, XHTML names are all in lowercase. Too bad Internet Explorer doesn’t understand true XHTML; I wouldn’t be surprised if Opera was purposely mimicking IE’s behavior as that doesn’t seem to be uncommon.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum