469,312 Members | 2,496 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,312 developers. It's quick & easy.

Need help with eval()

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

Sep 16 '05 #1
5 1240
ae*****@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
Sep 16 '05 #2
Lee
ae*****@gmail.com said:

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!


document.form_name.elements[i][property_name]=action;

Sep 17 '05 #3
Rob and Lee, many thanks....works great

Sep 17 '05 #4
ASM
ae*****@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
Sep 17 '05 #5
ae*****@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.nam edItem("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-HTM...ml#ID-75708506

elements
http://www.w3.org/TR/DOM-Level-2-HTM...ml#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-deve...tml#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
Sep 18 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

21 posts views Thread by Chris Reedy | last post: by
5 posts views Thread by Luis E Valencia | last post: by
8 posts views Thread by | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
reply views Thread by harlem98 | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.