473,799 Members | 3,085 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 51215
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
5661
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 = mi.Invoke(proxyInstance, paramsArray); where methodParams is an array of parameters where the value...
4
9772
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
4083
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
30793
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 me. Could someone explain when to use old-style parenthesized casts vs. the Convert() methods?
3
18281
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
3638
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 read button, I converted his VB to the C#. But the compiler complains:
1
5416
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 I can;t convert the image. I certainly don't want to upload it the the server filesystem, convert...
3
21424
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
16721
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 GetValue<T(string objName) { T results;
0
9687
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9541
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10484
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10228
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4141
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
2
3759
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.