|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic forname/fieldname
Hello,
I was wondering if I could do the following : can I change the formname and fieldname with an argument? This way I can re-use the script multiple times. My code (that doesn't work): ----------------- <script> function test(arg,arg2) { document.arg.arg2.value="yes"; } </script> <form name="frmtest"> <input type="text" name="test1" value="hello"> <input type="button" onclick="javascript:test('frmtest','test1');"> </form> ----------------- How can I make this work? Thanks in advance! |
|
#2
|
|||
|
|||
|
RE: Dynamic forname/fieldname
You neeed to use eval() for something like this. Change your function to:
Code:
function test(arg,arg2) {
eval('document.'+arg+'.'+arg2+'.value="yes"');
}
As you have it, the browser will look for an object(form) named 'arg' with an element(field) named 'arg2' instead of the value of those variables. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Client Side Things > Dynamic forname/fieldname |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|