473,387 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1327
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: Chris Reedy | last post by:
For everyone - Apologies for the length of this message. If you don't want to look at the long example, you can skip to the end of the message. And for the Python gurus among you, if you can...
4
by: Sarah | last post by:
Hi all. I have a form, and several text and image links on it that should submit the form with different actions. I prepared a simple page with just the code that's not working. PROBLEM:...
6
by: J Mox | last post by:
I have a function that changes which radio button is selected. I need to pass the form name to the function but not the field name and am doing so like: changeRadio(this.form); The function: ...
5
by: Darren Smith | last post by:
Hi There, I have a shopping cart app that displays products along with a textbox (to enter quantity) and an image button to add the item to the shopping cart. Please explain why my below...
5
by: Luis E Valencia | last post by:
I need a link on a datagrid, the link must have fields of the database Like this acciones.aspx?iddireccion=1&idindicador=4 Thanks
8
by: | last post by:
The problem lies here eval("document.TeeForm.amt.value(S+M)"); S and M suppose to add up and the total suppose to appear on the AMT field but it didn't. Any help? ...
1
by: Margaret101 | last post by:
Hi!! I'm trying to do some simple paging with goes to the database once and then shows and hides the results to display 3 items at a time. It uses a next and previous button. The next button works...
2
by: DC | last post by:
The Code <%@ import namespace="System" %> <%@ import namespace="System.Web" %> <%@ import namespace="System.Web.UI" %> <%@ import namespace="System.Web.UI.HtmlControls" %> <%@ import...
0
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
3
by: saundra | last post by:
Here is my error Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/truthat/public_html/verukasalt/admin/main.php(1) : eval()'d code(1) : eval()'d code(1)...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.