Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

eval() function problems.

Status
Not open for further replies.

sourabhjha

Programmer
Jan 13, 2002
121
IN
Hi,
I want to check whether the checkboxes in my JSP are checked or not.The checkboxes are generated dynamically and their names are: bean0.check,bean1.check,etc.

when I use 'eval' to access these checkboxes, it gives error on page, stating object expected.
the structure of checkbox:
<input type="checkbox" id="bean0.check" name = "bean0.check"
onclick="func('sometable',rowid)" />
Structure of javascript function:func('sometable',0){
var smvar=eval("document.Formname.bean" + rowid+"check").checked;
this gives me error. can anyone help?
 
You don't need to use eval for what you're doing. It's very clumsy and inefficient. Just use the proper method for accessing the forms and elements collections and it's easy:
Code:
var smvar = document.forms["Formname"].elements["bean" + rowid + ".check"].checked;


Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
They should remove documentation for eval from websites and books. There's like .001% situations where it is favorable to another method. Most of the time people use it to reference form objects which is just plain unneccessary.

-kaht

Looking for a puppy?

[small]Silky Terriers are small, relatively odorless dogs that shed no fur and make great indoor pets.[/small]
 
Agreed. I've found a few instances where it is invaluble, but then I've done some pretty advanced javascript coding. For most of what people do it is totally unnecessary.

I place part of the blame on people who insist on using the non-standard "document.formname.elementname.attribute" style for access to form elements instead of the collection notation, which is MUCH more flexible.

Tracy Dryden

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard. [dragon]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top