Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > textbox id is not defined error for firefox, works fine in IE

Reply
Thread Tools

textbox id is not defined error for firefox, works fine in IE

 
 
Stever1975
Guest
Posts: n/a
 
      10-12-2008
I'm working on something similiar to a shopping cart item page. There
is a table of items. Each item has an image, a textbox for the qty
and an image for the add button.
When the add image is clicked it adds the item to the cart array and
sums it if the item already exists in the cart.
This code works perfectly fine in Internet explorer and firefox, heck
I even tested it in chrome and it works.
So everything works fine in all browsers when it's just the table of
items and the javascript code. But when this code is Included into
another page ( the page with menu, footer, and header). It errors out
in firefox with the following error (works fine in other browsers):
txt9360303S is not defined
[Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
parseInt(eval(textbox + '.value'));

(the '...' is because the debugger could not display all the code)
Both pages are in the same directory.

I'm figuring that by including it in another page I'm some how messing
up the DOM. But I can't figure how. So I guess what I'm wondering is
there a particular firefox gotcha that would cause this.




Below is the javascript function I'm using and the html for one of the
items.



<table><tr><td><input type=text size=2 value=1 name='txt9360303S'
id='txt9360303S'></td><td><div id='additem' name='additem'
onClick=AddItem('936030/3S')><img src='btnAdd1.jpg' border=0></div></
td></tr></table>


The Javascript function:

var AddItem=function(Item){

textbox='txt' + Item.replace('/','')
Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
parseInt(eval(textbox + '.value'));
//DisplayItemQty(Item);
DisplayAllQty(Cart);
//alert(Display(Cart));

}


 
Reply With Quote
 
 
 
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-12-2008
Stever1975 wrote:
> [...] It errors out
> in firefox with the following error (works fine in other browsers):
> txt9360303S is not defined
> [Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
> parseInt(eval(textbox + '.value'));
>
> (the '...' is because the debugger could not display all the code)
> Both pages are in the same directory.
>
> I'm figuring that by including it in another page I'm some how messing
> up the DOM. But I can't figure how. So I guess what I'm wondering is
> there a particular firefox gotcha that would cause this.


Highly unlikely.

> [...]
> Below is the javascript function I'm using and the html for one of the
> items.
>
> <table><tr><td><input type=text size=2 value=1 name='txt9360303S'
> id='txt9360303S'></td><td><div id='additem' name='additem'
> onClick=AddItem('936030/3S')><img src='btnAdd1.jpg' border=0></div></
> td></tr></table>
>
>
> The Javascript function:
>
> var AddItem=function(Item){
>
> textbox='txt' + Item.replace('/','')
> Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
> parseInt(eval(textbox + '.value'));
> //DisplayItemQty(Item);
> DisplayAllQty(Cart);
> //alert(Display(Cart));
>
> }


Your markup is not Valid and your script code is atrocious. Both are hardly
legible. Once you fixed that, the former using <http://validator.w3.org/>
and the latter by applying <http://jibbering.com/faq/#eval> and other style
guides, you will probably see the problem clear enough by yourself so not to
ask this question again.

Incidentally, FAQ 5.35 should refer to FAQs 5.34 and 5.10 on how to avoid
eval().


PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>
 
Reply With Quote
 
 
 
 
Stever1975
Guest
Posts: n/a
 
      10-12-2008
On Oct 12, 5:48 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
wrote:
> Stever1975 wrote:
> > [...] It errors out
> > in firefox with the following error (works fine in other browsers):
> > txt9360303S is not defined
> > [Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
> > parseInt(eval(textbox + '.value'));

>
> > (the '...' is because the debugger could not display all the code)
> > Both pages are in the same directory.

>
> > I'm figuring that by including it in another page I'm some how messing
> > up the DOM. But I can't figure how. So I guess what I'm wondering is
> > there a particular firefox gotcha that would cause this.

>
> Highly unlikely.
>
>
>
> > [...]
> > Below is the javascript function I'm using and the html for one of the
> > items.

>
> > <table><tr><td><input type=text size=2 value=1 name='txt9360303S'
> > id='txt9360303S'></td><td><div id='additem' name='additem'
> > onClick=AddItem('936030/3S')><img src='btnAdd1.jpg' border=0></div></
> > td></tr></table>

>
> > The Javascript function:

>
> > var AddItem=function(Item){

>
> > textbox='txt' + Item.replace('/','')
> > Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
> > parseInt(eval(textbox + '.value'));
> > //DisplayItemQty(Item);
> > DisplayAllQty(Cart);
> > //alert(Display(Cart));

>
> > }

>
> Your markup is not Valid and your script code is atrocious. Both are hardly
> legible. Once you fixed that, the former using <http://validator.w3.org/>
> and the latter by applying <http://jibbering.com/faq/#eval> and other style
> guides, you will probably see the problem clear enough by yourself so not to
> ask this question again.
>
> Incidentally, FAQ 5.35 should refer to FAQs 5.34 and 5.10 on how to avoid
> eval().
>
> PointedEars
> --
> Prototype.js was written by people who don't know javascript for people
> who don't know javascript. People who don't know javascript are not
> the best source of advice on designing systems that use javascript.
> -- Richard Cornford, cljs, <f806at$ail$1$(E-Mail Removed)>


So I'm guessing you don't know the answer either...
 
Reply With Quote
 
David Mark
Guest
Posts: n/a
 
      10-13-2008
On Oct 12, 6:28*pm, Stever1975 <(E-Mail Removed)> wrote:
>
> So I'm guessing you don't know the answer either...


I'm guessing you will ignore the very realistic advice to validate
your markup, read the FAQ about eval, etc.

Good luck with your shopping cart application.
 
Reply With Quote
 
dhtml
Guest
Posts: n/a
 
      10-13-2008
Thomas 'PointedEars' Lahn wrote:
> Stever1975 wrote:



>
> Incidentally, FAQ 5.35 should refer to FAQs 5.34 and 5.10 on how to avoid
> eval().
>


Duly noted.

>
> PointedEars


Garrett

--
comp.lang.javascript FAQ <URL: http://jibbering.com/faq/ >
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-13-2008
On Oct 13, 8:28*am, Stever1975 <(E-Mail Removed)> wrote:
> On Oct 12, 5:48 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
> wrote:
>
>
>
> > Stever1975 wrote:
> > > [...] It errors out
> > > in firefox with the following error (works fine in other browsers):
> > > txt9360303S is not defined
> > > [Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine....]) +
> > > parseInt(eval(textbox + '.value'));

[...]
> > > The Javascript function:

>
> > > var AddItem=function(Item){

>
> > > textbox='txt' + Item.replace('/','')
> > > Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
> > > parseInt(eval(textbox + '.value'));
> > > //DisplayItemQty(Item);
> > > DisplayAllQty(Cart);
> > > //alert(Display(Cart));

>
> > > }

>
> > Your markup is not Valid and your script code is atrocious. *Both arehardly
> > legible. *Once you fixed that, the former using <http://validator.w3.org/>
> > and the latter by applying <http://jibbering.com/faq/#eval> and other style
> > guides, you will probably see the problem clear enough by yourself so not to
> > ask this question again.

[...]
>
> So I'm guessing you don't know the answer either...


No, he's hoping that when you go to the FAQ to read #5.35 you will
also read the following item, #5.36:

<URL: http://www.jibbering.com/faq/#globalPollution >


<FAQENTRY>

Re: FAQ 5.36

If the anchor name "globalPollution" is an attempt to link the anchor
text to the subject, it fails by being too general. I should be more
like "globalID" or "IDAsGlobalVar" similar. Cluttering the global
space with unneccessary variables is an issue, but it's not limited to
"globalising" ID attribute values.

</FAQENTRY>


--
Rob
 
Reply With Quote
 
Stever1975
Guest
Posts: n/a
 
      10-13-2008
On Oct 12, 10:59 pm, RobG <(E-Mail Removed)> wrote:
> On Oct 13, 8:28 am, Stever1975 <(E-Mail Removed)> wrote:
>
>
>
> > On Oct 12, 5:48 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
> > wrote:

>
> > > Stever1975 wrote:
> > > > [...] It errors out
> > > > in firefox with the following error (works fine in other browsers):
> > > > txt9360303S is not defined
> > > > [Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
> > > > parseInt(eval(textbox + '.value'));

> [...]
> > > > The Javascript function:

>
> > > > var AddItem=function(Item){

>
> > > > textbox='txt' + Item.replace('/','')
> > > > Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item]) +
> > > > parseInt(eval(textbox + '.value'));
> > > > //DisplayItemQty(Item);
> > > > DisplayAllQty(Cart);
> > > > //alert(Display(Cart));

>
> > > > }

>
> > > Your markup is not Valid and your script code is atrocious. Both are hardly
> > > legible. Once you fixed that, the former using <http://validator.w3.org/>
> > > and the latter by applying <http://jibbering.com/faq/#eval> and other style
> > > guides, you will probably see the problem clear enough by yourself so not to
> > > ask this question again.

> [...]
>
> > So I'm guessing you don't know the answer either...

>
> No, he's hoping that when you go to the FAQ to read #5.35 you will
> also read the following item, #5.36:
>
> <URL:http://www.jibbering.com/faq/#globalPollution>
>
> <FAQENTRY>
>
> Re: FAQ 5.36
>
> If the anchor name "globalPollution" is an attempt to link the anchor
> text to the subject, it fails by being too general. I should be more
> like "globalID" or "IDAsGlobalVar" similar. Cluttering the global
> space with unneccessary variables is an issue, but it's not limited to
> "globalising" ID attribute values.
>
> </FAQENTRY>
>
> --
> Rob


Thanks.
Realized what he was saying later on, and he is right Some of us are
newbies and toting out words like 'atrocious' is just not helpful.
How the community reacts in their forums is extremely important to
language growth and acceptance.


thanks again
 
Reply With Quote
 
dmark@cinsoft.net
Guest
Posts: n/a
 
      10-13-2008
On Oct 13, 3:47*pm, Stever1975 <(E-Mail Removed)> wrote:
> On Oct 12, 10:59 pm, RobG <(E-Mail Removed)> wrote:
>
>
>
> > On Oct 13, 8:28 am, Stever1975 <(E-Mail Removed)> wrote:

>
> > > On Oct 12, 5:48 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>
> > > wrote:

>
> > > > Stever1975 wrote:
> > > > > [...] It errors out
> > > > > in firefox with the following error (works fine in other browsers):
> > > > > txt9360303S is not defined
> > > > > [Break on this error] Cart[Item]=parseInt(Cart[Item]==undefine...]) +
> > > > > parseInt(eval(textbox + '.value'));

> > [...]
> > > > > The Javascript function:

>
> > > > > var AddItem=function(Item){

>
> > > > > textbox='txt' + Item.replace('/','')
> > > > > Cart[Item]=parseInt(Cart[Item]==undefined ? 0 : Cart[Item])+
> > > > > parseInt(eval(textbox + '.value'));
> > > > > //DisplayItemQty(Item);
> > > > > DisplayAllQty(Cart);
> > > > > //alert(Display(Cart));

>
> > > > > }

>
> > > > Your markup is not Valid and your script code is atrocious. *Bothare hardly
> > > > legible. *Once you fixed that, the former using <http://validator..w3.org/>
> > > > and the latter by applying <http://jibbering.com/faq/#eval> and other style
> > > > guides, you will probably see the problem clear enough by yourself so not to
> > > > ask this question again.

> > [...]

>
> > > So I'm guessing you don't know the answer either...

>
> > No, he's hoping that when you go to the FAQ to read #5.35 you will
> > also read the following item, #5.36:

>
> > <URL:http://www.jibbering.com/faq/#globalPollution>

>
> > <FAQENTRY>

>
> > Re: FAQ 5.36

>
> > If the anchor name "globalPollution" is an attempt to link the anchor
> > text to the subject, it fails by being too general. *I should be more
> > like "globalID" or "IDAsGlobalVar" similar. *Cluttering the global
> > space with unneccessary variables is an issue, but it's not limited to
> > "globalising" ID attribute values.

>
> > </FAQENTRY>

>
> > --
> > Rob

>
> Thanks.
> Realized what he was saying later on, and he is right Some of us are
> newbies and toting out words like 'atrocious' is just not helpful.


Yes it is, when it gets you to pay attention to the points made (e.g.
validate your code, don't use eval.)

> How the community reacts in their forums is extremely important to
> language growth and acceptance.


How you react to good advice is extremely important to your growth and
acceptance. Your code is atrocious and perhaps you should put off
writing a shopping cart application until you learn the language.
There are enough atrocious scripts out there as it is. Thank you for
your cooperation.
 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      10-13-2008
On Oct 14, 5:47 am, Stever1975 <(E-Mail Removed)> wrote:
> On Oct 12, 10:59 pm, RobG <(E-Mail Removed)> wrote:
> > On Oct 13, 8:28 am, Stever1975 <(E-Mail Removed)> wrote:
> > > On Oct 12, 5:48 pm, Thomas 'PointedEars' Lahn <(E-Mail Removed)>

[...]
> > > > Your markup is not Valid and your script code is atrocious. Both are hardly
> > > > legible. Once you fixed that, the former using <http://validator.w3.org/>
> > > > and the latter by applying <http://jibbering.com/faq/#eval> and other style
> > > > guides, you will probably see the problem clear enough by yourself so not to
> > > > ask this question again.

> > [...]

>
> > > So I'm guessing you don't know the answer either...

>
> > No, he's hoping that when you go to the FAQ to read #5.35 you will
> > also read the following item, #5.36:

>
> > <URL:http://www.jibbering.com/faq/#globalPollution>

[...]
> Thanks.
> Realized what he was saying later on, and he is right Some of us are
> newbies and toting out words like 'atrocious' is just not helpful.
> How the community reacts in their forums is extremely important to
> language growth and acceptance.


Yes. If Thomas’ social skills were even half of his technical skills
he’d probably be a nice bloke. But they ain’t - c'est la vie.

I always imagine his scolding missives being delivered by a portly
grandmother with a wagging finger and a big grin, perhaps the other
hand has a fat slab of toast smeared in braunschweiger.


--
Rob
 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      10-13-2008
RobG wrote:
> On Oct 14, 5:47 am, Stever1975 <(E-Mail Removed)> wrote:
>> Realized what he was saying later on, and he is right Some of us are
>> newbies and toting out words like 'atrocious' is just not helpful.
>> How the community reacts in their forums is extremely important to
>> language growth and acceptance.


And googlodytes with a ridiculous From header like you who know nothing,
don't want to learn anything, and start whining when they are told that this
behavior is not accepted, are lusers that are the last thing the language(s)
need(s). So turn around 180 degrees or go away, silently, please.

> Yes. If Thomas’ social skills were even half of his technical skills
> he’d probably be a nice bloke. But they ain’t - c'est la vie.


You don't know me.

> I always imagine his scolding missives being delivered by a portly
> grandmother with a wagging finger and a big grin, perhaps the other
> hand has a fat slab of toast smeared in braunschweiger.


Certainly not Braunschweiger, as I am a vegetarian, but you got the picture


HTH & HAND

PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
boxcfed is not defined - error in firefox, works fine in IE mehstg1319 Javascript 2 04-14-2008 09:18 PM
#if (defined(__STDC__) && !defined(NO_PROTOTYPE)) || defined(__cplusplus) Oodini C Programming 1 09-27-2005 07:58 PM
boutique and fine art royalty free images - free fine art image offer Andrew Mowat Digital Photography 0 09-14-2004 05:35 AM
Microsoft Access DSNLess connection error, works fine in .ASP page, not in aspx code. Derrick ASP .Net 2 08-26-2004 07:12 PM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM



Advertisments