Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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~

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    394
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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

  • #3
    New Coder
    Join Date
    Dec 2006
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder Arbitrator's Avatar
    Join Date
    Mar 2006
    Location
    Splendora, Texas, United States of America
    Posts
    3,276
    Thanks
    28
    Thanked 272 Times in 266 Posts
    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.
    For every complex problem, there is an answer that is clear, simple, and wrong.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •