|
Prev: DOM 2 Events
Next: runtime error: object required?
From: aesahab on 16 Sep 2005 19:21 Folks, I'm writing this command: form_name.elements[i].property_name = action; //action = true/false I want to pass the property_name as dynamic value so if the function passes "disabled" it'll be like: form_name.elements[i].disabled = true; I tried to do that with eval but couldn't get it to work! Any ideas
From: RobG on 16 Sep 2005 19:42 aesahab(a)gmail.com wrote: > Folks, > > I'm writing this command: > form_name.elements[i].property_name = action; //action = true/false > > I want to pass the property_name as dynamic value so if the function > passes "disabled" it'll be like: > form_name.elements[i].disabled = true; > > I tried to do that with eval but couldn't get it to work! > As usual, there is no need for 'eval' at all. Whenever dot notation doesn't work, try square brackets: <script type="text/javascript"> function doThing( thing, prop, value ) { thing[prop] = value; } </script> <form action=""> <input type="text" name="fred" <input type="button" value="Disable Fred" onclick=" doThing( this.form.fred, 'disabled', 'true'); "> </form> -- Rob
From: aesahab on 16 Sep 2005 20:25 Rob and Lee, many thanks....works great
From: ASM on 16 Sep 2005 22:16 aesahab(a)gmail.com wrote: > Folks, > > I'm writing this command: > form_name.elements[i].property_name = action; //action = true/false > > I want to pass the property_name as dynamic value so if the function > passes "disabled" it'll be like: > form_name.elements[i].disabled = true; > > I tried to do that with eval but couldn't get it to work! I do not understand your question (about eval ...) <html> <script type="text/javascript"> function truc(action) { var d = document.form_name.elements[0]; d.property_name = action; d.disabled = d.property_name; d.value = d.property_name; } </script> <form name="form_name"> <input type=text> </form> <button onclick="truc(false);">False</button> <button onclick="truc(true);">True</button> </html> -- Stephane Moriaux et son [moins] vieux Mac
From: Gérard Talbot on 18 Sep 2005 17:17 aesahab(a)gmail.com a ýcrit : > Folks, > > I'm writing this command: > form_name.elements[i].property_name = action; //action = true/false > > I want to pass the property_name as dynamic value so if the function > passes "disabled" it'll be like: > form_name.elements[i].disabled = true; > > I tried to do that with eval Never use eval(); 99% of the time, there is a better method than resorting to eval(). but couldn't get it to work! > > Any ideas > document.forms.namedItem("form_name").elements.namedItem("property_name").disabled = action; // action = true|false W3C DOM 2 compliant HTML collection namedItem This method retrieves a Node using a name. http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-75708506 elements http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479 Other ways to get scriptable access to form controls: Using Web Standards in Your Web Pages Accessing Elements with the W3C DOM http://www.mozilla.org/docs/web-developer/upgrade_2.html#dom_access comp.lang.javascript FAQ: How do I get the value of a form control? http://jibbering.com/faq/#FAQ4_13 Gýrard -- remove blah to email me
|
Pages: 1 Prev: DOM 2 Events Next: runtime error: object required? |