value is null or not an object, but its defined?

C

cwizard

I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not an object... the
function is like so:

function calc_total()
{
var x,i,base,margin,total,newmargin,newtotal;
base = document.frmKitAmount.txtTotalKitValue.value;
margin = document.frmKitAmount.margin.value/100;
total = document.frmKitAmount.total.value;
newtotal = (1 + margin) * base;
document.frmKitAmount.total.value = FormatNumber(newtotal,2,false,true);
}

formatnumber() is elsewhere and it should work fine... the error happens on
the part where i assign the variable base to be equal to the form value
txtTotalKitValue... which is there..... i'm a newbie, and i'm working with
code thats already in place trying to add a couple little functions to
basically just display a marked up price in a text box below a current
price...

to see this page in action please go to http://67.66.56.168/gss/Corporate
and in the URL change msg=Fast to msg=QLG and hit enter. go to any of the
yellow tabs on the top. I appreciate any replies

<form name="frmKitAmt">
<input type="hidden" name="itemname"
value="<%=Server.HTMLEncode(objKitList.Name)%>">
<input type="hidden" name="imglink" value="<%=imgLink & objKitList.Image%>">
<input type="hidden" name="description"
value="<%=Server.HTMLEncode(objKitList.Description)%>">
<table border= "0" cellspacing="1" cellpadding="0" width="95%">
<%If objKitList.CallForPrice then%>
<input type="hidden" name="txtTotalKitValue">
<tr>
<td class=siteNav1TD valign="middle" colspan="3">
<img src="images/blank.gif">
</td></tr>
<%Else%>
<tr>
<td class=siteNav1TD valign="middle">
<table width="100%">
<tr>
<td colspan="3" align="center" valign="middle">
<font face="Verdana" size="2" color="#ffffff"><strong>Base
Price:</strong> </font>
</td>
<td>
<font face="Verdana" size="2"
color="#ffffff"><strong><%=g_currencyString%>&nbsp;<%=FormatNumber(objkitlis
t.price * Markup,2)%></strong></font>
</td>
<td valign="middle">
<font face="Verdana" size="2" color="#FFFFFF"><strong>Your Price:
<%=g_currencyString%> </strong></font>
<input type="text" name="txtTotalKitValue"
value="<%=FormatNumber(objKitList.Price * Markup,2)%>" size="10"
onFocus="this.blur();">
</td>
</tr>
<tr>
<td colspan="4" align="center" valign="middle">
<font face="Verdana" size="2" color="#FFFFFF"><strong>Markup:
</strong></font>
<input type="text" name="margin" value="0" size="10"
onblur="calc_total();">
</td>
<td valign="middle">
<font face="Verdana" size="2" color="#FFFFFF"><strong>End Price:
<%=g_currencyString%> </strong></font>
<input type="text" name="total" value="<%=FormatNumber(objKitList.Price
* Markup,2)%>" size="10">
</td>
</tr>
</table>
</td>
<td class=siteNav1TD valign="middle" align="center"<%if Not
objKitList.ClubTotals then%>colspan="2"<%End if%> >
<font face="Verdana" size="1" color="#FFFFFF"><b>Quantity :</b><br>
<input name="qty" type="text" size="4" maxlength="4" value="<%If
objKitList.Qty > 0 Then%><%=objKitList.Qty%><%Else%>1<%End If%>"></font>
</td>
</tr>
<%End if%>


<tr>
<td colspan="3" height="20"><font face="Verdana" size="1">To take a
printable
version of this Kit <a href="javascript:printkit();"
class="msn"><strong>Click here.</strong></a></font></td>
</tr>
<tr>
<td><font face="verdana" size=1><b>Item Name</b></td>
<%if Not objKitList.ClubTotals and not objKitList.CallForPrice then%>
<td align="center"><font face="verdana" size=1><b>Price</b></td>
<%End if%>
<td align="center"><font face="verdana" size=1><b>Qty</b></td>
</tr>
<!--
</table>-->
</form>
 
C

cwizard

Then it is probably because document.frmKitAmount.txtTotalKitValue
doesn't exist. Actually an informative error message.

How can it not exist, the form field is there... its part of the source if
you look at it, there are values assigned.. I don't understand how it is
null.
I recommend:
var base = document.forms['frmKitAmount'].elements['txtTotalKitValue'].value;
for guaranteed compatability with all current and future browsers
(it's part of the W3C DOM, whereas having the form name as a property
of the document object isn't).

That looks fine, I used that and it didn't change the results.
We can't use server-side code for anything. The error is in the code
that is sent to the client!
However, the obvious guess would be that this If-test is false,
so the input with name "txtTotalKitValue" doesn't exist in the
page that is sent to the client.

No, this if-test is not false because the kit isn't set up as "Call for
Price"

Thanks for trying!
 
L

Lasse Reichstein Nielsen

cwizard said:
I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not an object...

Then it is probably because document.frmKitAmount.txtTotalKitValue
doesn't exist. Actually an informative error message.
base = document.frmKitAmount.txtTotalKitValue.value;

I recommend:
var base = document.forms['frmKitAmount'].elements['txtTotalKitValue'].value;
for guaranteed compatability with all current and future browsers
(it's part of the W3C DOM, whereas having the form name as a property
of the document object isn't).
<%If objKitList.CallForPrice then%>
<input type="hidden" name="txtTotalKitValue">

We can't use server-side code for anything. The error is in the code
that is sent to the client!
However, the obvious guess would be that this If-test is false,
so the input with name "txtTotalKitValue" doesn't exist in the
page that is sent to the client.

/L
 
A

Ang Talunin

Hey,

I've tried to make you're source a little easier:

<html>
<head>
<script>
function calc_total()
{
base = document.frmKitAmount.txtTotalKitValue.value;
margin = document.frmKitAmount.margin.value/100;
total = document.frmKitAmount.total.value;
newtotal = (1 + margin) * base;
document.frmKitAmount.total.value = newtotal //insert your function:
FormatNumber(newtotal,2,false,true);
}
</script>
</head>
<body>
<form name=frmKitAmount>
Base : <input type=text name=txtTotalKitValue><br>
Margin : <input type=text name=margin><br>
Total: <input type=text name=total><br>
<input type=button onClick=calc_total() value="Calc">
</form>
</body>
</html>

The problem I think is that there isn't a <input> with the name
"frmKitAmount".

But if you wanne fool around with javascript, just learn it from the
beginning.
Make simpel code, so it's easier to find problems....

good luck,

A.T.
 
C

cwizard

The problem I think is that there isn't a <input> with the name
"frmKitAmount".

No the form name is frmKitAmount, the object is txtTotalKitValue which is
already set and is actually updated by another function.
But if you wanne fool around with javascript, just learn it from the
beginning.

I wish I had the time, the place I work for just doesn't understand the
concept.
 
D

Douglas Crockford

But if you wanne fool around with javascript, just learn it from the
I wish I had the time, the place I work for just doesn't understand the
concept.

It seems unlikely to me that an employer would not want its employees to be
competent. It is much more common to see employees who lie about their
qualifications. Where is this place you work for that doesn't understand the
concept of hiring honest, intelligent people?
 
C

cwizard

It seems unlikely to me that an employer would not want its employees to be
competent. It is much more common to see employees who lie about their
qualifications. Where is this place you work for that doesn't understand the
concept of hiring honest, intelligent people?

They understand the concept of honest intelligent people, the problem is the
project that I'm working on is a first for me... I'm working with an
existing page that already has quite a few jscript functions on it, its got
3 different forms on the same page and they want it done, oh yesterday....
the actual thing that I want to accomplish, I already did in a separate page
http://www.basscomputers.com/marginbox.asp but somehow the exact same
procedure I used there isn't working here. Its frustrating for me because I
dont want to be a burden on anyone, I can't figure out why the hell its
telling me theres no object when the form is THERE and the field is THERE
and its not mispelled and there's a number assigned to it.

I'm pretty decent at hacking code, I just can't figure out whats going on
here and I'm stumped!
 
L

Lasse Reichstein Nielsen

cwizard said:
How can it not exist, the form field is there... its part of the source if
you look at it, there are values assigned.. I don't understand how it is
null.

You need to look at the code that is sent to the browser. Have you
tried that, and verified that the input tag is present? Since there is
obviously a bug *somewhere*, it might be on in the server code, so the
input tag is never written. In that case, you might be chasing a
client side error that is only a symptom of the real error.
No, this if-test is not false because the kit isn't set up as "Call for
Price"

Maybe it should be there, but that won't change that the browser can't
find the input element.

/L
 
C

cwizard

var base = document.frmKitAmt.txtTotalKitValue.value;
var margin = document.frmKitAmount.margin.value/100;

If you notice, you have a different form name for margin. It
should read

var margin = document.frmKitAmt.margin.value/100;

I'm so stupid.

THIS is exactly why I came to you guys!!!!

HAHAHAHAHAHAHAH! THANKS!
 
A

Alice

cwizard said:
I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not an object... the

Looking at the code you supply in your message and checking it out on the
the actual page the only form name i can find is
<form name="frmKitAmt">

frmKitAmount does not exist so far as I can tell
 
M

Michael Winter

I'm calling on a function from within this form, and there are values set
but every time it gets called I get slammed with a run time error...
document.frmKitAmount.txtTotalKitValue is null or not an object... the
function is like so:

You'll kick yourself when you read this...
function calc_total()
{
var x,i,base,margin,total,newmargin,newtotal;
base = document.frmKitAmount.txtTotalKitValue.value;
margin = document.frmKitAmount.margin.value/100;
total = document.frmKitAmount.total.value;
newtotal = (1 + margin) * base;
document.frmKitAmount.total.value = FormatNumber(newtotal,2,false,true);
}

<form name="frmKitAmt">
<snip>

Notice the name of the form? In your code above, you reference
frmKitAmount, when it should in fact be frmKitAmt. Making that change
("Amt" to "Amount", or visa versa) should fix things, but I'd like to make
a few suggestions, if I may.

When refering to controls in forms, use the "collections syntax":

document.forms['form_name'].elements['control_name']

This syntax is supported by far more browsers than the common:

document.form_name.control_name

When you use intrinsic events (onclick, etc), place this META element in
the HEAD block to specify the scripting language. It's not strictly
necessary (browsers will interpret your page without it), but according to
the HTML 4 specification, it is required:

<META http-equiv="Content-Script-Type" content="text/javascript">

Don't use the language attribute in SCRIPT elements; the type attribute is
mandatory and is sufficient to indicate the language. Certainly don't do
what Ang Talunin did and omit both of them.

<SCRIPT type="text/javascript">

You should specify a DOCTYPE for your pages. Again, browsers will
interpret your pages without one, but that's not the point - the HTML
specification requires one.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

There are other DOCTYPEs, but as you use deprecated elements and
attributes (FONT, bgcolor, etc), this one is the most appropriate. As you
do use style sheets in the page you showed here, I would consider revising
the document to be HTML Strict compliant where presentation is acheived
with style sheets only, and HTML only provides structure.

Don't use JavaScript pseudo-URIs (href="javascript:...") - they can cause
problems. Instead, use onclick events. Whilst I was looking through your
HTML, I found this:

<a href="javascript:CheckConfig('add');" class="msn">
<img src="images/add_to_cart.gif" border="0"></a>

You could achieve the same thing with:

<IMG src="images/add_to_cart.gif" onclick="CheckConfig('add')">

One advantage with this is that if the user doesn't have JavaScript
enabled, they don't get transported to some non-existant location.

If you do want to use an anchor to display something using JavaScript, try
to make the href attribute point to something useful:

<A href="next_page.html" onclick="some_javascript()">...</A>

Hope that helps,
Mike


http://www.w3.org/TR/html4/ The HTML 4.01 Specification
 
A

Ang Talunin

I'm pretty decent at hacking code, I just can't figure out whats going on
here and I'm stumped!

Then you should strip those page's down to just the forms and the functions
and post them all...
 
E

Eric Bohlman

I'm so stupid.

THIS is exactly why I came to you guys!!!!

HAHAHAHAHAHAHAH! THANKS!

That sort of error is extremely common because of the phenomenon known as
"psychological set" which is the built-in human tendency to adjust our
perceptions to match our expectations (Douglas Adams made it the basis for
his SEP field). Everyone who's ever debugged a program or proofread a
manuscript has spent long hours staring at his creation and seeing what he
meant to write rather than what he actually wrote.

Often a fresh pair of eyes is exactly what's needed to catch this sort of
problem, but do keep in mind the advice another poster gave you earlier in
this thread; try stripping down your code to produce a bare-minimum test
case. More often than you'd think, the mere process of doing that disrupts
the "SEP" mechanism enough to make your mistake visible to you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top