Connecting Tech Pros Worldwide Help | Site Map

value is null or not an object -- after submitting a few times

AC
Guest
 
Posts: n/a
#1: Jul 20 '05
I hope someone can tell me why this is not working. I have a form that
dynamically creates the code below. This is for one product and there are
about 10 to 50 products that are listed depending on what manufacturer the
user selects. After "buying" a few products (4-8) they user gets the error
message: 'QUANTITY.value' is null or not an object.

Do you see a workaround/fix for this?

I posted this on February 19, 2004 under the title 'value is null or not an
object -- after a few submits' and received some syntax tips. The
formatting has been applied and I hope someone can offer some programmatic
help.


HTML (calling code):
=====================================
<tr>
<td width='120' valign='middle' align='center'><font size=-1>Widget
A</font></td>
<td width='50' valign='middle' align='center'><font size=-1>Length
6</font></td>
<td width='54' valign='middle' align='center'><font size=-1>Width
47</font></td>
<td width='50' valign='middle' align='center'><font
size=-1>$4.40</font></td>

<td width='50' valign='middle' align='center'>
<FORM NAME='frmOrder18ea' action='products3.asp'>
<input type='hidden' name='ID_NUM' value='18'>
<input type='hidden' name='NAME' value='Widget A'>
<input type='hidden' name='PRICE' value='4.4'>
<font size=-1><input type='text' size='3' name='QUANTITY' value='0'
onChange='this.value=CKquantity(this.value)'></input>&nbsp;</font>
</FORM>
</TD>
<td width='50' valign='middle' align='center'>
<font size=-1>$99.00 &nbsp;</font>
</td>
<td width='53' valign='middle' align='center'>
<FORM NAME='frmOrder18bx' action='products3.asp'>
<input type='hidden' name='ID_NUM' value='18'>
<input type='hidden' name='NAME' value='Widget A big'>
<input type='hidden' name='PRICE' value='99'>
<font size=-1><input type='text' size='3' name='QUANTITY'
value='0'></input>&nbsp;</font>
</FORM>
</TD>
<td>
<FORM NAME='frmSubmitMe18' action='products3.asp'>
<input type="button" value="Buy" onClick="ProcessBuys(frmOrder18ea,
frmOrder18bx )">
</FORM>
</td>
</tr>
=====================================

Javascript code:
=====================================
<script language="JavaScript">
<!--
function ProcessBuys(first, second) { //, second) { //Handles multiple items

if(first.QUANTITY.value>0){
AddToCart(first);
//alert('bye '+first.name+' bye');
}

if(second.QUANTITY.value>0){
AddToCart(second);
//alert('abt '+first.name+' abt');
}

return false;
}
//-->
</Script>
=====================================


Thanks in advance,
--AC


Ivo
Guest
 
Posts: n/a
#2: Jul 20 '05

re: value is null or not an object -- after submitting a few times



"AC" <AC@No.spam> wrote in message
news:EyrZb.65076$KV5.59700@nwrdny01.gnilink.net...[color=blue]
> I hope someone can tell me why this is not working. I have a form that
> dynamically creates the code below. This is for one product and there are
> about 10 to 50 products that are listed depending on what manufacturer the
> user selects. After "buying" a few products (4-8) they user gets the[/color]
error[color=blue]
> message: 'QUANTITY.value' is null or not an object.[/color]

You posted a lot of HTML defining three forms, baptized "frmOrder18ea",
"frmOrder18bx" and "frmSubmitMe18". In the first two forms we do indeed find
elements named "QUANTITY". The first of those even calls a javascript
function "CKquantity()" onchange.
You also posted some javascript, but not function CKquantity(). The onsubmit
function ProcessBuys() that we see expects two global variables "first" and
"second", each with a property called "QUANTITY" with a property called
"value". It looks like CKquantity() should prepare these variable but
somehow doesn't.
The whole setup is a bit funny, two forms without submit element, and a
third to submit them. I'm sure there is (or has been) a reason for that.
Also, giving global variables the same names as your form elements is asking
for trouble. There may be hundreds of form elements called Q on a page, but
there is variable Q until explicitly set.
HTH
Ivo
[color=blue]
> <script language="JavaScript">
> <!--
> function ProcessBuys(first, second) { //, second) { //Handles multiple[/color]
items[color=blue]
>
> if(first.QUANTITY.value>0){
> AddToCart(first);
> //alert('bye '+first.name+' bye');
> }
>
> if(second.QUANTITY.value>0){
> AddToCart(second);
> //alert('abt '+first.name+' abt');
> }
>
> return false;
> }
>[/color]


Ivo
Guest
 
Posts: n/a
#3: Jul 20 '05

re: value is null or not an object -- after submitting a few times



"AC" <AC@No.spam> wrote in message
news:EyrZb.65076$KV5.59700@nwrdny01.gnilink.net...[color=blue]
> I hope someone can tell me why this is not working. I have a form that
> dynamically creates the code below. This is for one product and there are
> about 10 to 50 products that are listed depending on what manufacturer the
> user selects. After "buying" a few products (4-8) they user gets the[/color]
error[color=blue]
> message: 'QUANTITY.value' is null or not an object.[/color]

You posted a lot of HTML defining three forms, baptized "frmOrder18ea",
"frmOrder18bx" and "frmSubmitMe18". In the first two forms we do indeed find
elements named "QUANTITY". The first of those even calls a javascript
function "CKquantity()" onchange.
You also posted some javascript, but not function CKquantity(). The onsubmit
function ProcessBuys() that we see expects two global variables "first" and
"second", each with a property called "QUANTITY" with a property called
"value". It looks like CKquantity() should prepare these variable but
somehow doesn't.
The whole setup is a bit funny, two forms without submit element, and a
third to submit them. I'm sure there is (or has been) a reason for that.
Also, giving global variables the same names as your form elements is asking
for trouble. There may be hundreds of form elements called Q on a page, but
there is variable Q until explicitly set.
HTH
Ivo
[color=blue]
> <script language="JavaScript">
> <!--
> function ProcessBuys(first, second) { //, second) { //Handles multiple[/color]
items[color=blue]
>
> if(first.QUANTITY.value>0){
> AddToCart(first);
> //alert('bye '+first.name+' bye');
> }
>
> if(second.QUANTITY.value>0){
> AddToCart(second);
> //alert('abt '+first.name+' abt');
> }
>
> return false;
> }
>[/color]


AC
Guest
 
Posts: n/a
#4: Jul 20 '05

re: value is null or not an object -- after submitting a few times


Please see the response to your original message.

"Ivo" <no@thank.you> wrote in message
news:4036860b$0$201$abc4f4c3@news.wanadoo.nl...[color=blue]
>[/color]
<snip/>


AC
Guest
 
Posts: n/a
#5: Jul 20 '05

re: value is null or not an object -- after submitting a few times


Ivo,

Thanks for the reply. The two forms (frmOrderXXXX) are sent to the
ProcessBuys function from the frmSubmitMeXX form using the button. Once the
form objects are sent to the ProcessBuys function it uses them as "First"
and "Second" variables. These objects are used to encapsulate the
properties (name, price, quantity, etc) and send them to another function.

The problem is that after a few "buys" (submissions) the form objects do not
contain their properties when sent to the ProcessBuys function. Is the
number of forms a problem? I can have up to about 150 total (50 products x
3 forms).

The CKquantity function performs well so it does not matter for this
problem.

Thanks again,
--AC


Michael Winter
Guest
 
Posts: n/a
#6: Jul 20 '05

re: value is null or not an object -- after submitting a few times


On Fri, 20 Feb 2004 23:11:01 +0100, Ivo <no@thank.you> wrote:

[snip]
[color=blue]
> You posted a lot of HTML defining three forms, baptized "frmOrder18ea",
> "frmOrder18bx" and "frmSubmitMe18". In the first two forms we do indeed
> find elements named "QUANTITY". The first of those even calls a
> javascript function "CKquantity()" onchange.
> You also posted some javascript, but not function CKquantity(). The
> onsubmit function ProcessBuys() that we see expects two global
> variables "first" and "second", [...][/color]

Those are function arguments, which makes them local, not global.
[color=blue]
> [...] each with a property called "QUANTITY" with a property called
> "value". It looks like CKquantity() should prepare these variable but
> somehow doesn't.
> The whole setup is a bit funny, two forms without submit element, and a
> third to submit them. I'm sure there is (or has been) a reason for that.[/color]

I agree that the arrangement is strange. The better way to organise groups
of controls is using the FIELDSET element or, if you must, tables. In
either case, there should only be one FORM element. However, without
seeing the document there isn't a way to reliably say which is better.
[color=blue]
> Also, giving global variables the same names as your form elements is
> asking for trouble.[/color]

The use of the identifiers frmOrder18ea and frmOrder18bx in the call

ProcessBuys(frmOrder18ea,frmOrder18bx)

is a badly executed attempt to pass references of the respective forms to
the function, ProcessBuys(). It is not using global variables with the
same name as forms, it using form names as global variables (subtle
difference), and IE practice. What the OP should use is:

ProcessBuys(document.frmOrder18ea,document.frmOrde r18bx)

or

ProcessBuys(document.forms['frmOrder18ea'],
document.forms['frmOrder18bx'])

Without doing this, users of non-IE browsers will not be able to use this
functionality, and probably, the page as a whole.
[color=blue]
> There may be hundreds of form elements called Q on a page, but there
> is variable Q until explicitly set.[/color]

I can't honestly say I know what you mean there.

[snip]

Mike

--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
Michael Winter
Guest
 
Posts: n/a
#7: Jul 20 '05

re: value is null or not an object -- after submitting a few times


On Fri, 20 Feb 2004 17:34:28 GMT, AC <AC@No.spam> wrote:
[color=blue]
> I hope someone can tell me why this is not working. I have a form that
> dynamically creates the code below. This is for one product and there
> are about 10 to 50 products that are listed depending on what
> manufacturer the user selects. After "buying" a few products (4-8)
> they user gets the error message: 'QUANTITY.value' is null or not an
> object.
>
> Do you see a workaround/fix for this?[/color]

Nothing that you have posted in this thread, with one (or possibly two)
exceptions, should cause this problem.
[color=blue]
> I posted this on February 19, 2004 under the title 'value is null or not
> an object -- after a few submits' and received some syntax tips. The
> formatting has been applied and I hope someone can offer some
> programmatic help.[/color]

As such, I can do little more at the moment than provide more syntax tips.
Do read them, though.

[snip]
[color=blue]
> <td width='50' valign='middle' align='center'>
> <FORM NAME='frmOrder18ea' action='products3.asp'>
> <input type='hidden' name='ID_NUM' value='18'>
> <input type='hidden' name='NAME' value='Widget A'>
> <input type='hidden' name='PRICE' value='4.4'>
> <font size=-1><input type='text' size='3' name='QUANTITY' value='0'
> onChange='this.value=CKquantity(this.value)'></input>&nbsp;</font>[/color]

There is no such thing as a closing INPUT tag. Get rid of it.

[snip]
[color=blue]
> <td width='53' valign='middle' align='center'>
> <FORM NAME='frmOrder18bx' action='products3.asp'>
> <input type='hidden' name='ID_NUM' value='18'>
> <input type='hidden' name='NAME' value='Widget A big'>
> <input type='hidden' name='PRICE' value='99'>
> <font size=-1><input type='text' size='3' name='QUANTITY'
> value='0'></input>&nbsp;</font>[/color]

The same criticism here as above.

[snip]
[color=blue]
> <FORM NAME='frmSubmitMe18' action='products3.asp'>
> <input type="button" value="Buy" onClick="ProcessBuys(frmOrder18ea,
> frmOrder18bx )">[/color]

This call is likely to fail in browsers besides IE. You should not use
element names as global references. Instead use either,

ProcessBuys(document.frmOrder18ea,document.frmOrde r18bx)

or

ProcessBuys(document.forms['frmOrder18ea'],
document.forms['frmOrder18bx'])

[snip]
[color=blue]
> <script language="JavaScript">[/color]

The type attribute is required. The language attribute is deprecated. Use:

<script type="text/javascript">
[color=blue]
> <!--[/color]

Script hiding is an obsolete practice. Remove the SGML comment delimiters.
[color=blue]
> function ProcessBuys(first, second) { //, second) { //Handles multiple
> items
>
> if(first.QUANTITY.value>0){[/color]

It might be more appropriate to convert the text string, value, into a
number before performing that comparison. I'm not sure off hand how it
will be treated, especially if value contains non-numeric characters.

[snip]

I don't think that the number of forms in the page can cause what is
happening. If it is that, then the browser is broken. Even so, it might be
an idea to do it anyway as it's poor use of HTML.

As I seriously doubt the changes above will yield anything except better
compatibility and a more valid document, you'll have to post more code or
even a URL.

Mike

--
Michael Winter
M.Winter@blueyonder.co.invalid (replace ".invalid" with ".uk" to reply)
AC
Guest
 
Posts: n/a
#8: Jul 20 '05

re: value is null or not an object -- after submitting a few times


Sent you the page in an email.

--AC


AC
Guest
 
Posts: n/a
#9: Jul 20 '05

re: value is null or not an object -- after submitting a few times


Michael Winter figured it out. I have to look at why the code is doing this
but the solution is as follows:

=======================
Initially, I couldn't reproduce the problem but with some luck and the
trusty alert box, I found the cause: you don't use unique names for the
forms in all cases. For example, Spanish (Each) uses the form
name, "frmOrder40ea". This name is also used by Carlos #3. When you
pass document.forms['frmOrder40ea'] to ProcessBuys(), you pass a
collection of all form elements with that name, not a form reference.

There are two solutions:

1) Ensure that all form names are unique.
2) Alter the call with all duplicates so that you index the array. With
the above example, you would call ProcessBuys() with
document.forms['frmOrder40ea'][0] for Spanish, and
document.forms['frmOrder40ea'][1] for Carlos.

Good luck,
Mike
=======================

I will now have to see why my server-side code is creating a form name
twice. It shouldn't as I am incrementing the form numbers when I create
them.

Thank you Michael again.

--
AC


Closed Thread