Connecting Tech Pros Worldwide Forums | Help | Site Map

javascript

martin
Guest
 
Posts: n/a
#1: Dec 12 '05
Can someone please help me with an issue I have with Firefox that generates
in the console below when running the code below.Strange thing is that IE
runs it no problem. I don't think it's an async error though as I have seen
some posts.
Martin


Error: fValue has no properties



//---------Qty ASP Checking start
var WkKM = 1;
var WkUnits = "";
var unitslen;
var WkValue = 0;
if ( (Units != "") && (ASP != "" ) ) {
unitslen = Units.length;
TempKM = Units.substr(unitslen-1,1).toUpperCase();
if ( (TempKM== "K" || TempKM == "M") ) {
if (TempKM == "K") {
WkKM = 1000;
}
else if (TempKM == "M") {
WkKM = 1000000;
}
Units = Units.substr(0,unitslen-1);
}

WkUnits = Units* WkKM;

if ( (WkUnits == "") || (IsNumeric(ASP) == false) )
WkValue = 0;
else
WkValue = WkUnits*ASP;
}
if (WkValue <5000)
errmsg = errmsg + "There is a $5000 minimum value for each registration.
\n";
else {
//---------------Insert Value
var fValue=document.getElementById("Value");
fValue.value=WkValue;
} //---------Qty ASP Checking start
var WkKM = 1;
var WkUnits = "";
var unitslen;
var WkValue = 0;
if ( (Units != "") && (ASP != "" ) ) {
unitslen = Units.length;
TempKM = Units.substr(unitslen-1,1).toUpperCase();
if ( (TempKM== "K" || TempKM == "M") ) {
if (TempKM == "K") {
WkKM = 1000;
}
else if (TempKM == "M") {
WkKM = 1000000;
}
Units = Units.substr(0,unitslen-1);
}

WkUnits = Units* WkKM;

if ( (WkUnits == "") || (IsNumeric(ASP) == false) )
WkValue = 0;
else
WkValue = WkUnits*ASP;
}
if (WkValue <5000)
errmsg = errmsg + "There is a $5000 minimum value for each registration.
\n";
else {
//---------------Insert Value
var fValue=document.getElementById("Value");
fValue.value=WkValue;
}


Randy Webb
Guest
 
Posts: n/a
#2: Dec 12 '05

re: javascript


martin said the following on 12/12/2005 5:14 AM:[color=blue]
> Can someone please help me with an issue I have with Firefox that generates
> in the console below when running the code below.Strange thing is that IE
> runs it no problem. I don't think it's an async error though as I have seen
> some posts.
> Martin
>
>
> Error: fValue has no properties[/color]

Without seeing the HTML, first guess is that you have a form field named
"Value" and that the following line:

var fValue=document.getElementById("Value");

In IE, it will incorrectly pick it up by name. Mozilla is not so
forgiving. If it is a form element, then use the forms collection:

var fValue= document.forms['formName'].elements['Value']

Not sure I would name a form field Value though. Too easy to confuse it
with the .value property of form fields.


--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
RobG
Guest
 
Posts: n/a
#3: Dec 12 '05

re: javascript


martin wrote:[color=blue]
> Can someone please help me with an issue I have with Firefox that generates
> in the console below when running the code below.Strange thing is that IE
> runs it no problem. I don't think it's an async error though as I have seen
> some posts.
> Martin
>
>
> Error: fValue has no properties
>[/color]

That may be because of the issue Randy has identified, the other (which
you refer to as an 'async error') is that you are running the function
before fValue exists - either the function is run before the document
has finished loading or before some other script that creates fValue has
done its job.

[color=blue]
> //---------Qty ASP Checking start
> var WkKM = 1;
> var WkUnits = "";
> var unitslen;
> var WkValue = 0;
> if ( (Units != "") && (ASP != "" ) ) {
> unitslen = Units.length;
> TempKM = Units.substr(unitslen-1,1).toUpperCase();[/color]

The substr() method exists only for backward compatibility with some
older implementations of ECMAScript, it has been removed from the
normative part of Ed 3 (see Appendix B part 2). It may be a good idea
to use the substring method instead, its behaviour is slightly different:

substr(start, length) versus substring(start, end)


If end is lower than start, end & start will be swapped. substring
returns all characters from start up to but not including end. If no
end is specified, then all characters from start to the end of the
string are returned. If no start is specified, zero is used.

You can get rid of the unitslen variable too (I think you are just
trying to strip the last character from Units):

TempKM = Units.substring(Units.length-1).toUpperCase();


[color=blue]
> if ( (TempKM== "K" || TempKM == "M") ) {
> if (TempKM == "K") {
> WkKM = 1000;
> }
> else if (TempKM == "M") {
> WkKM = 1000000;
> }
> Units = Units.substr(0,unitslen-1);[/color]

Here you would use:

Units = Units.substring(0,Units.length-1);


Though now the 'Units' variable is actually a number. I think maybe you
should evaluate the names you are giving variables, it isn't good to
mask the true nature of a variable, it can make debugging and
maintenance a pain.


[...]


--
Rob
Closed Thread