Second, let me state that this is not the typical "getElementById not working Firefox" post.
Third, there are pieces of this code that I am not at liberty to display, change, discuss, or re-implement. As far as this question is concerned, this means that (1) I cannot use 3rd party libraries, which is why I've implemented my own Ajax script... besides, it's simple and effective... and (2) I know coding HTML tables to display layout is a snafu, but since I'm not alone on this, the tables won out over DIVs.
And finally... the scenario:
I've got something over 2000 lines of code (HTML & JS) that pertains to this, but using alert() and various server-side debugging methods, I've come to the comfortable realization that my problem lies in this function within my Ajax function.
Expand|Select|Wrap|Line Numbers
- /* This function is called asynchronously when the server returns a result from an AJAX request */
- function ajaxRequestCallback(){
- if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete") {
- var str = xmlHttp.responseText;
- var strparts = str.split( "&" );
- var numParts = strparts.length;
- for( var j = 0; j < numParts; j++ ) {
- var item = strparts[j];
- var elems = item.split( ":" );
- var name = elems[0];
- var value = Base64Decode( elems[1] );
- /* The situation in question will display "infoUserName" for 'name' */
- alert( "Getting object with ID '" + name + "'." );
- /* The problem is here */
- var o = document.getElementById( name );
- /* 'if' removed for testing using Firefox's error console */
- /* if( o ) { */
- /* Firefox Error Console says 'o is null' at this point.
- o.innerHTML = value;
- /* } */
- }
- }
- }
Expand|Select|Wrap|Line Numbers
- <table class='bodyContainer'>
- <tr>
- <td style='text-align: right; vertical-align: top; width: 100px;'>
- <label for='tbUserName'>User Name:</label></td>
- <td style='text-align: left; vertical-align: top; width: 197px;'>
- <input id='tbUserName' name='tbUserName' type='text' OnKeyUp='checkUserName();' class='textbox' style='width: 193px' value='' /></td>
- <td style='text-align: left; vertical-align: top; width: 297px;'>
- <!-- Here is the element being retrieved from the JavaScript -->
- <span id='infoUserName'>User name must be supplied.</span></td>
- </tr>
- <tr>
- <td style='text-align: right; vertical-align: top; width: 100px;'>
- <label for='tbPassword'>Password:</label></td>
- <td style='text-align: left; vertical-align: top; width: 197px;'>
- <input id='tbPassword' name='tbPassword' type='password' OnKeyUp='checkPasswd();' class='textbox' style='width: 193px' /></td>
- <td style='text-align: left; vertical-align: top; width: 297px;'>
- <span id='infoPassword'>Your password is too short</span></td>
- </tr>
- <!-- More rows occur, but they work perfectly! -->
- </table>
Any thoughts?
I apologize for not being able to provide a 100% working model here. It may be noteworthy for recreating this problem that the checkPasswd function just checks for length and compares against a RegEx for 'strong' vs. 'weak' and checkUserName() initiates the AJAX request to see if the UserName exists already.
TIA
Cy