![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
#3
| |||
| |||
|
|
I tried changing var radio2check = eval(formname+'.'+fieldname); to var radio2check = eval('document.'+formname.name+'.'+fieldname); |
|
and it appears to work. If anyone has a better solution, please let me know. |
#4
| |||
| |||
|
|
I tried changing var radio2check = eval(formname+'.'+fieldname); to var radio2check = eval('document.'+formname.name+'.'+fieldname); and it appears to work. If anyone has a better solution, please let me know. |
#5
| |||
| |||
|
|
J Mox wrote: I tried changing var radio2check = eval(formname+'.'+fieldname); to var radio2check = eval('document.'+formname.name+'.'+fieldname); Eval is almost never, ever needed - follow the link from the FAQ on square bracket notation: URL:http://www.jibbering.com/faq/faq_not..._brackets.html A guess at what you might need is: var radio2check = document.forms[formname].elements[fieldname]; and it appears to work. If anyone has a better solution, please let me know. Your eval method may work, but it is less than optimal. -- Rob |
#6
| |||
| |||
|
|
J Mox wrote: I tried changing var radio2check = eval(formname+'.'+fieldname); to var radio2check = eval('document.'+formname.name+'.'+fieldname); and it appears to work. If anyone has a better solution, please let me know. If the latter "works" then the variable (paramerter?) - formname - is not a string representation of a name but an object that has a property called - name -. It is also an object with the property - name - where that name happens to be the name of a FORM Element object. That is unlikely to be a coincidence and so I would deduce that - formname - is a reference to an object that is a FORM element object, indeed it is _the_ form element object. So some confusion has been introduced by giving it a name that actually conceals its real nature. If you do - eval('document.'+formRef.name); - what you get back is - formRef -, a reference to the FORM object that you started with, so you can skip that. if you do - eval('fromRef.'+fieldName) - you are doing the same as - formRef[fieldname] - but slower and more indirectly. var radio2check = formname[fieldname]; - should "work" at least as effectively as the - eval - and is; shorter, simpler, faster and more direct (and so easier to debug and maintain). (but do change the - formname - variable name) A general rule for newcomers to javascript would be that if you are considering using - eval - then you have the opportunity to learn something new that will not use - eval - and be objectively better than the - eval - use. Richard. |
#7
| |||
| |||
|
|
Thanks for the link. If I was passing the actual form name as a string, which is what I mistakenly thought I was in effect doing when I passed this.form to the function, then I think your solution would work but since I am passing what I have now come to understand is a object referencing a form the following works. var radio2check = formname[fieldname]; |
![]() |
| Thread Tools | |
| Display Modes | |
| |