By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,483 Members | 1,727 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,483 IT Pros & Developers. It's quick & easy.

Need help with eval()

P: n/a
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
Share this Question
Share on Google+
5 Replies


P: n/a
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

P: n/a
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

P: n/a
Rob and Lee, many thanks....works great

Sep 17 '05 #4

P: n/a
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

P: n/a
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.