Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-28-2006, 02:29 AM   PM User | #1
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
Small JS Browser Problem

I have the following code:

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:

Code:
<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 is offline   Reply With Quote
Old 12-28-2006, 02:40 AM   PM User | #2
lavinpj1
Regular Coder

 
Join Date: Sep 2005
Posts: 394
Thanks: 1
Thanked 0 Times in 0 Posts
lavinpj1 is an unknown quantity at this point
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
lavinpj1 is offline   Reply With Quote
Old 12-28-2006, 06:44 AM   PM User | #3
vegu
New Coder

 
Join Date: Dec 2006
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
vegu is on a distinguished road
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

Code:
if (server.indexOf('OK') == -1) {
	errorFields = errorFields + "Database Server Address\n"
}
__________________
http://demo.vegui.org - vegUI AJAX framework
http://www.landsofkazram.com - browser based graphical MMORPG
vegu is offline   Reply With Quote
Old 12-28-2006, 07:27 AM   PM User | #4
Arbitrator
Senior Coder

 
Arbitrator's Avatar
 
Join Date: Mar 2006
Location: Splendora, Texas, United States of America
Posts: 2,900
Thanks: 5
Thanked 188 Times in 185 Posts
Arbitrator is on a distinguished road
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.
__________________
Please for the love of god stop making IE. You current "browser"s cause me to cry every day. —Phil *
Arbitrator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:31 PM.


Advertisement
Log in to turn off these ads.