473,549 Members | 2,921 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

convert string to object reference

I know there's an easy answer to this which is escaping me:
--------------------------------------------------------------------------
-----------------------
I have clickable thumb images which pass the image info to a window open script
to display a larger version of the image along with a description of the image.
The image info comes from the image element; the description string is in a
hidden form var with the same name as the image element.

// example:
<a... <image name='imagename 1' ... >/a>
<input type='hidden' name='imagename 1' value='image descriptor1' .....

Problem:
inserting the image name argument into document.myform .imagename1.val ue
to get the value of the hidden field yields a string, not the value of that
form field.

Doing this:
var imdesc = "document.myfor m." + imagename1 + ".value"

yields a string var called imdesc with a value of
"document.myfor m.imagename1.va lue"

But I don't want that string, I want its object reference value.

There is something very basic here I'm overlooking... so the question is:
How do I convert the string to have it literally interpreted as the value of
the document.form + imagename1 argument ??

Many many thanks in advance,

Jim

Jul 20 '05 #1
5 51201
In article <20************ *************** @mb-m23.aol.com>,
ji*******@aol.c omNoSpam enlightened us with...
var imdesc = "document.myfor m." + imagename1 + ".value"


var imdesc = document.myform[imagename1].value

-------------------------------------------------
~kaeli~
Hey, if you got it flaunt it! If you don't, stare
at someone who does. Just don't lick the TV screen,
it leaves streaks.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace
-------------------------------------------------
Jul 20 '05 #2
try

var imdesc = eval("document. myform." + imagename1 + ".value")
"JimMenees" <ji*******@aol. comNoSpam> wrote in message
news:20******** *************** ****@mb-m23.aol.com...
I know there's an easy answer to this which is escaping me:
--------------------------------------------------------------------------
-----------------------
I have clickable thumb images which pass the image info to a window open script to display a larger version of the image along with a description of the image.

The image info comes from the image element; the description string is in a hidden form var with the same name as the image element.

// example:
<a... <image name='imagename 1' ... >/a>
<input type='hidden' name='imagename 1' value='image descriptor1' .....

Problem:
inserting the image name argument into document.myform .imagename1.val ue
to get the value of the hidden field yields a string, not the value of that form field.

Doing this:
var imdesc = "document.myfor m." + imagename1 + ".value"

yields a string var called imdesc with a value of
"document.myfor m.imagename1.va lue"

But I don't want that string, I want its object reference value.

There is something very basic here I'm overlooking... so the question is:
How do I convert the string to have it literally interpreted as the value of the document.form + imagename1 argument ??

Many many thanks in advance,

Jim

Jul 20 '05 #3
> try

var imdesc = eval("document. myform." + imagename1 + ".value")


No! Don't try that. That is extremely bad style. The correct way to write it is

var imdesc = document.myform[imagename1].value;

It is almost always incorrect to use the eval() function.

http://www.crockford.com/javascript/survey.html

Jul 20 '05 #4
Please tell me why ?
"Douglas Crockford" <no****@laserli nk.net> wrote in message
news:bk******** **@sun-news.laserlink. net...
try

var imdesc = eval("document. myform." + imagename1 + ".value")
No! Don't try that. That is extremely bad style. The correct way to write

it is
var imdesc = document.myform[imagename1].value;

It is almost always incorrect to use the eval() function.

http://www.crockford.com/javascript/survey.html

Jul 20 '05 #5
> > > try
var imdesc = eval("document. myform." + imagename1 + ".value")
No! Don't try that. That is extremely bad style.
The correct way to write it is var imdesc = document.myform[imagename1].value; It is almost always incorrect to use the eval() function. See http://www.crockford.com/javascript/survey.html
Please tell me why ?


That is a fair question. The faq (http://jibbering.com/faq/#FAQ4_40) recommends
avoiding eval(), but doesn't say why. There are lots of good reasons to avoid
it.

First, it is a crutch. It allows weak programmers to remain weak programmers by
avoiding learning about simple language features such as subscript notation.
JavaScript is a complete programming language. It is always better to use the
language's features correctly. It is always worse to synthesize features with
eval().

eval() is expensive. It invokes the JavaScript compiler every time it is called.

It has portability problems. Some interpreters vary in the context that eval()
operates in.

It makes it harder to reason about the correctness of a program. Verification
tools (http://www.crockford.com/javascript/lint.html) cannot validate the
correctness of an eval() expression.

Error detection is postponed from compile time to run time. This makes testing
more difficult and increases the likelihood that your errors will be shown to
users.

eval() can fail if the expression is not syntactically correct. The security
properties of eval() are horrible.

There are lots of very bad JavaScript books out there that routinely use eval().
If you have a bad one, chuck it in the trash right now and go out and get a good
one.

When you are reviewing scripts and libraries, routinely reject code that makes
inapporpriate use of eval(). Almost all uses are inappropriate.

Jul 20 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5637
by: phancey | last post by:
I am trying to invoke a web service method dynamically. I have created a generic function that takes a method name, string of parameters and calls the web method using System.Reflection: MethodInfo mi = proxyInstance.GetType().GetMethod(methodName); object paramsArray = (object)methodParams.ToArray(typeof(object)); object result =...
4
9715
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a numeric value according to an arbitrary regular expression.
2
4069
by: Kevin B Ebert | last post by:
Today, I ran into something I didn't quite expect. I'm sure there is a logical explanation for it so I want to post it and see if anyone can explain the difference to me. I came across a situation when I wanted to see if a public variable inside a struct was null or not. Sample code below: namespace SampleConsole { /// <summary>
7
30763
by: Jim Bancroft | last post by:
Hi everyone, A basic one here, I think. I haven't found the pattern yet, but sometimes when I cast a variable to another type using the "C" style cast operator the compiler refuses to play along. It says it's an invalid cast. However, if I use the Convert.ToInt32() method (for example) things will work. At least, that's how it appears to...
3
18259
by: James | last post by:
Has anyone written a utility to convert a C# form to C++.net? i.e. to convert "using System.Data" to "using namespace System::Data" etc
3
3622
by: dale zhang | last post by:
Hi, I am trying to read an image from MS Access DB based on the following article: http://www.vbdotnetheaven.com/Code/Sept2003/2175.asp The article author is using PictureBox for windows application, while I am doing for web. I can only find Image from web forms control and HTML control. This may be the root cause of my problem. For...
1
5395
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a web form to upload a TIFF image (scanned images) and convert it to a JPEG before I insert it into SQL Server. The file upload part works great, but...
3
21405
by: Mark Kamoski | last post by:
Hi-- What is the difference between Convert.ToString(obj) and CType(obj, String)? (Assume obj is a variable of type Object.) Please advise. Thank you.
7
16632
by: groups | last post by:
This is my first foray into writing a generic method and maybe I've bitten off more than I can chew. My intent is to have a generic method that accepts a value name and that value will be returned from the source. My first attempt was as follows; (please ignore that error handling is not present in this example) public T...
0
7560
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7487
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7758
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
6098
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5401
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5126
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1978
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1093
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.