473,396 Members | 1,968 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,396 software developers and data experts.

Client-Side Object Reference Quandry

Please consider the following two if() structures. The first one fails, yet
the second works. Why? FWIW, I got the syntax of the first out of a working
page. I figured moving it to another page would be harmless. What's going on
here? The only major difference between the two pages that I can see so far
is that in the new page (where the first if() structure fails), the control
imgname is in a <form runat="server" method="post"> whereas in the page it
came from, there is no <Form> at all on the page. Could that have some
relevance?

// This one fails
if(v_incoming != "")
{
imgname.value = v_incoming; // this errors out with message: 'imgname' is
undefined.
}

// This one works
if(v_incoming != "")
{
var obj_imgname = document.all("imgname");
obj_imgname.value = v_incoming; //no problems
}

here is the definition of imgname:
<input type="text" id="imgname" size="40" value="http://" NAME="imgname">

Thanks!
Nov 18 '05 #1
3 1099
yes, having a form defined matters.

<html>
<body>
<input type=text name=imgname id=imgname1>
<form name=myForm>
<input type=text name=imgname id=imgname1>
</form>
</body>
</html>

document.imgname.value //refers to the first one
document.myForm.imgname.value //refers to the second (as it is a child
of myForm)

document.all("imgname") // is obsolete and
should never be used - would return an array

document.getElementsByTag('imgname')[0] // referes to the first one
document.getElementsByTag('imgname')[1] // referes to the second one

as id are required to be unique in a document unlike names, the following
should work

document.getElementById('imgname1') // referes to the first one
document.getElementById('imgname2') // referes to the second one

-- bruce (sqlwork.com)
"Fred" <th*************@skruspammers.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Please consider the following two if() structures. The first one fails, yet the second works. Why? FWIW, I got the syntax of the first out of a working page. I figured moving it to another page would be harmless. What's going on here? The only major difference between the two pages that I can see so far is that in the new page (where the first if() structure fails), the control imgname is in a <form runat="server" method="post"> whereas in the page it
came from, there is no <Form> at all on the page. Could that have some
relevance?

// This one fails
if(v_incoming != "")
{
imgname.value = v_incoming; // this errors out with message: 'imgname' is undefined.
}

// This one works
if(v_incoming != "")
{
var obj_imgname = document.all("imgname");
obj_imgname.value = v_incoming; //no problems
}

here is the definition of imgname:
<input type="text" id="imgname" size="40" value="http://" NAME="imgname">

Thanks!

Nov 18 '05 #2
In your first example - imagename is undefined. An easier way to do this is to use your form name.

example:

<form name="Form1">
<input type="text" id="imgname" size="40" value="http://" NAME="imgname">
</form>

if(v_incoming != "")
{
Form1.imgname.value = v_incoming;
}

Bobby Ryzhy
bobby@ domain below
http://weekendtech.net

On Mon, 12 Jul 2004 14:36:37 -0700, "Fred" <th*************@skruspammers.com> wrote:
Please consider the following two if() structures. The first one fails, yet
the second works. Why? FWIW, I got the syntax of the first out of a working
page. I figured moving it to another page would be harmless. What's going on
here? The only major difference between the two pages that I can see so far
is that in the new page (where the first if() structure fails), the control
imgname is in a <form runat="server" method="post"> whereas in the page it
came from, there is no <Form> at all on the page. Could that have some
relevance?

// This one fails
if(v_incoming != "")
{
imgname.value = v_incoming; // this errors out with message: 'imgname' is
undefined.
}

// This one works
if(v_incoming != "")
{
var obj_imgname = document.all("imgname");
obj_imgname.value = v_incoming; //no problems
}

here is the definition of imgname:
<input type="text" id="imgname" size="40" value="http://" NAME="imgname">

Thanks!


Bobby Ryzhy
bobby @ domain below
http://weekendtech.net
Nov 18 '05 #3
Wow, thanks. I guess I'll have to take JavaScript a bit more seriously!
"bruce barker" <no***********@safeco.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
yes, having a form defined matters.

<html>
<body>
<input type=text name=imgname id=imgname1>
<form name=myForm>
<input type=text name=imgname id=imgname1>
</form>
</body>
</html>

document.imgname.value //refers to the first one
document.myForm.imgname.value //refers to the second (as it is a child of myForm)

document.all("imgname") // is obsolete and
should never be used - would return an array

document.getElementsByTag('imgname')[0] // referes to the first one
document.getElementsByTag('imgname')[1] // referes to the second one

as id are required to be unique in a document unlike names, the following
should work

document.getElementById('imgname1') // referes to the first one
document.getElementById('imgname2') // referes to the second one

-- bruce (sqlwork.com)
"Fred" <th*************@skruspammers.com> wrote in message
news:%2***************@TK2MSFTNGP11.phx.gbl...
Please consider the following two if() structures. The first one fails, yet
the second works. Why? FWIW, I got the syntax of the first out of a

working
page. I figured moving it to another page would be harmless. What's going on
here? The only major difference between the two pages that I can see so

far
is that in the new page (where the first if() structure fails), the

control
imgname is in a <form runat="server" method="post"> whereas in the page

it came from, there is no <Form> at all on the page. Could that have some
relevance?

// This one fails
if(v_incoming != "")
{
imgname.value = v_incoming; // this errors out with message: 'imgname'

is
undefined.
}

// This one works
if(v_incoming != "")
{
var obj_imgname = document.all("imgname");
obj_imgname.value = v_incoming; //no problems
}

here is the definition of imgname:
<input type="text" id="imgname" size="40" value="http://" NAME="imgname">
Thanks!


Nov 18 '05 #4

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

Similar topics

2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
2
by: Raquel | last post by:
How do I know whether the 'runtime client' and the 'application development client' are installed on my machine? When I issue the command "db2licm -l", it gives the following output: Product...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
2
by: Frank Swarbrick | last post by:
I am trying to understand "client authentication" works. My environment is DB2/UDB LUW 8.2 on zSeries SLES9 as the database server and DB2 for VSE 7.4 as the client. We currently have DB2/LUW set...
0
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function...
4
MMcCarthy
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, I’ve come to appreciate well defined project scopes. A project scope is a common understanding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
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...
0
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...

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.