• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to retrieve Checkbox state

 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 240
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I'm adding a row dynamically using JS.That row will contain a checkbox and hyperlink.
I'm able to get this done.But when i do a document.forms[0].checkboxname.checked i'm getting an error,It says it's undefined.


with this code i'm able to add a row.

But I also want to use the checkbox, is it possible to use it?

I'm doing a document.forms[0].chk it says it's undefined..

Is it not possible to use a dynamically added checkbox,I thought the DOM tree would in the browser's memory and it's possible to use the checkbox.
[ August 09, 2007: Message edited by: Srikkanth Mohanasundaram ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64173
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure why it's not working for you, but before you spend a whole lot more time on this, be aware that using refereces like document.forms[0] is very old-fashioned and error prone. (What if a new form gets added to the page before this form? Your code is broken!)

What I tend to do is to assign id values to elements that I need to reference and use document.getElementById() to directly and unequivically reference the element.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason it is not working is because the browser in use is IE and it does not assign the name attribute when you use DOM methods.

Do a view source on this page: http://pascarello.brinkster.net/examples/testNewForm.html and you can see how to get the name to added to the element.

Eric
 
Srikkanth Mohanasundaram
Ranch Hand
Posts: 240
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
-->Eric
Thanks that was very useful,I was breaking my head over this issue for 2 days.

-->Bear
That was a good suggestion,but i'm not supposed tweak any working code


I should have come here 2 days back

Regards,
Srikkanth.M
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic