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

js version difference question?

Status
Not open for further replies.

BobMCT

IS-IT--Management
Sep 11, 2000
756
US
[sad]I recently upgraded the components on one of my web servers from Ubuntu 8.04 to 12.04 followed by newer versions of Apache, PHP, et al. On my sites that use js functions to alter field attributes they suddenly stopped working. I've been beating my head in trying to figure out what changed. Also, I am NOT a js developer. I do just enough as needed (aka: be dangerous). My current versions of components are:
Apache 2.2.22, php 5.4.9-4
and I know that the js runs in the client side browser but as it is a development question I am posting here.

Here's a little snippet of code that runs on an onChange event:

// function to obtain selected game parameters and hide/unhide input blocks
function cnl_setPrompts() {
var _maxe=Number(Ginfo['_maxe']);
var _bmaxe=Number(Ginfo['_bmaxe']);
var _maxb=_bmaxe+10;
// Alter Selection Headings
cnl_setHide('_snh1','inline');
cnl_setHide('_snh2','inline');
// Alter Winning Number Fields
// alert('cnl_setPrompts: _maxe='+_maxe+' _bmaxe='+_bmaxe+' _maxb='+_maxb); //####
for(x=1;x<=10;x++) {
eid='_sn'+x;
action='none';
if (x <= _maxe) { action='inline'; }
cnl_setHide(eid, action);
}
// Now Alter bonus Number fields
for(x=11;x<=12;x++) {
eid='_sn'+x;
action='none';
if (x <= _maxb) { action='inline'; }
cnl_setHide(eid, action);
}
document.getElementById('_maxe').innerHTML=_maxe;
document.getElementById('_bmaxe').innerHTML=_bmaxe;
document.getID._sdate.focus();
}
//***************************************************************************
// function to obtain selected game parameters and hide/unhide input blocks
function cnl_setHide(eid, action) {
document.getElementById(eid).style.display=action; <<====<<<
}

The line identified by the arrow pointer is failing with the error that the ein is NULL. I've used alerts as well as firebug and web developer to monitor the content of that field and it all seems just fine.

Does anyone have any idea why I would receive that error (other than the obvious "its NULL"?

Again, I don't know why but this occurred only AFTER updating the server components.
Anything else I should be checking for? Oh, and whenever I try to alert most fields I only see Nan which didn't happen before. I know that Nan indicates Not a Number and ein is a string, NOT a number.

Thanks all for any ideas. [ponder]
 
as an aside, I'd suggest setting the action and x vars in cnl_setPrompts to a private variable.

Code:
[b][COLOR=#0000FF]var[/color][/b] action[COLOR=#990000];[/color]
[b][COLOR=#0000FF]var[/color][/b] x[COLOR=#990000];[/color] [i][COLOR=#9A1900]//or comma delimited var action,x;[/color][/i]

as for the rest, I suspect that the reason why it is failing is that the relevant ids do not exist. if you do the operation in two steps hopefully the error should disappear

Code:
[b][COLOR=#0000FF]function[/color][/b] [b][COLOR=#000000]cnl_setHide[/color][/b][COLOR=#990000]([/color]eid[COLOR=#990000],[/color] action[COLOR=#990000])[/color][COLOR=#FF0000]{[/color]
[tab][b][COLOR=#0000FF]var[/color][/b] ctl [COLOR=#990000]=[/color] document[COLOR=#990000].[/color][b][COLOR=#000000]getElementById[/color][/b][COLOR=#990000]([/color]eid[COLOR=#990000]);[/color]
[tab][b][COLOR=#0000FF]if[/color][/b][COLOR=#990000]([/color]ctl[COLOR=#990000])[/color] style[COLOR=#990000].[/color]display [COLOR=#990000]=[/color] action[COLOR=#990000];[/color] [i][COLOR=#9A1900]//<<====<<<[/color][/i]
[COLOR=#FF0000]}[/color]
 
jpadie,

Comments well taken. But I forgot to include a snippet of the html code its trying to reference. Here is a part:

<span id="_snh2" class="hide bold">Numbers to Search:</span>
<input class="hide" id="_sn1" name="_sn1" type="text" size="1" maxlength="2" value="$_sn1" />
<input class="hide" id="_sn2" name="_sn2" type="text" size="1" maxlength="2" value="$_sn2" />
.
.
.
So its questionable that the element is not found. The error being thrown states that the identifier refereced (field) is NULL.

So in my cnl_setHide function the eid apparently is NULL. But normally when examined within cnl_setPrompts is is displayed as valid content. If I set the variables within the functions and continue to pass them by name, will both functions be able to see the value(s) by process of parameter passing?

Thanks again.
 
remember that the loop is looking for ids _sn1 through 12. are you wholly certain that all of these exist, in all cases?

in which case does the error still appear when you substitute your code with mine?

also I'm not sure what server side you are using, but if it is PHP then that code won't work. you will need

Code:
<input class="hide" id="_sn1" name="_sn1" type="text" size="1" maxlength="2" value="[red]<?php echo $_sn1;?>[/red]" />
<input class="hide" id="_sn2" name="_sn2" type="text" size="1" maxlength="2" value="[red]<?php echo $_sn2;?>[/red]" />

or the shortcode variant (if you have that turned on)

Code:
value="<?=$_sn1;?>"

or you could use heredoc

Code:
echo <<<HTML
<span id="_snh2" class="hide bold">Numbers to Search:</span>
<input class="hide" id="_sn1" name="_sn1" type="text" size="1" maxlength="2" value="$_sn1" />
<input class="hide" id="_sn2" name="_sn2" type="text" size="1" maxlength="2" value="$_sn2" />
HTML;

I see nowhere in cnl_setPrompts where eid could be null as passed to the helper function. (although I have heard before that IE sometimes has trouble without spaces between operands I have never seen this myself.)

Code:
for (var x = 1; x <= 10; x++){
eid = '_sn' + x;
...
}

in any event, if eid is null (or 0, false, zero length string) then you should be able to capture it in the helper function

Code:
function cnl_setHide(eid, action){
    if( !eid) return false;
    var ctl = document.getElementById(eid);
    if(ctl) style.display = action; //<<====<<<
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top