473,804 Members | 2,787 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

document.all[txtObj] works but document.getEle mentById[txtObj] fails

wk
hi,
in my code
document.all[txtObj].value works but
document.getEle mentById[txtObj].value fails.
any ideas why?

Jul 23 '05 #1
5 1612


wk wrote:

in my code
document.all[txtObj].value works but
document.getEle mentById[txtObj].value fails.


document.getEle mentById is a function you should call in the form
document.getEle mentById('strin g-with-element-id')
so throw out the square brackets you have and correctly call
document.getEle mentById().
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2
hi wk,

getElementById( ) gets only one element that u specified with its id i
think, so it must be used something like this.
function foo(txtObj) {//txtObj is the objects id
var val=document.ge tElementById(tx tObj).value;
//...;
}

wk wrote:
hi,
in my code
document.all[txtObj].value works but
document.getEle mentById[txtObj].value fails.
any ideas why?


Jul 23 '05 #3
wk
the problem is that the the txtObj part in
document.getEle mentById[txtObj*].value, is coming froma string made of
comma separated name of objects such as 'txtObj,txtObj2 ,txtABC'. So i
need to split them, and them use them as actual objects IDs. How to go
about it?

document.getEle mentById(tx*tOb j).value syntax fails, as txtObj is a
string at the moment. Can i somehow convert the string or cast it to an
object?

Jul 23 '05 #4
"wk" <sa******@gmail .com> writes:
document.getEle mentById(tx*tOb j).value syntax fails, as txtObj is a
string at the moment.


That is not why it fails. The argument to document.getEle mentById should
be a string. If it fails, it's because the document doesn't contain an
element with that id.

(And please fix your news client to not insert arbitrary "-"'s in your
text).
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #5
wk wrote:
document.getEle mentById(tx*tOb j).value syntax fails, as txtObj is a
string at the moment.


document.getEle mentById(), as well as Microsoft's document.all()
indeed do expect a string as (an optional first, in document.all's
case) argument.

If you have a comma separated list of IDs, and want to get an array
of elements as a result, you might use something like:

function getElementsById s(sCSIDList) {
var aRV = [], aIDs, i, j, o;
if (typeof sCSIDList == "string") {
aIDs = txtObj.split(/,/);
if (document.getEl ementByID) {
for (i=0; i<aIDs.length; i++) {
aRV[i] = document.getEle mentById(aIDs[i]);
}
}
else if (document.all) {
// ...
}
}
return aRV;
}

ciao, dhgm

Jul 23 '05 #6

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

Similar topics

1
2153
by: Gerd Güldenast | last post by:
Hi, I am having a problem with a replication over a Modem-Connection, which works fine over LAN. Has anyone experienced this problem before? Settings are: 2 SQL Servers 2000, SP3 on Windows 2000 Publischer Database ist about 3GB, Subscriber DB about 1,5GB Publisher and Subscriber are connected via 56Kbit Dial-Up --> The Replication worked fine now this way for about 6 Months now!
14
24244
by: David Blickstein | last post by:
I have some XML documents that I want to open in a web browser and be automatically translated to HTML via XSLT. I'm using an xml-stylesheet processing command in a file called "girml.xml". This all works in Internet Explorer, but doesn't work with Firefox. In both IE and Firefox this works: <?xml-stylesheet type="text/xsl" encoding="UTF-8" href="makehtml.xslt" version="1.0"?>
17
4617
by: rox.scott | last post by:
Can someone please explain why this happens? The expected output is 3, but uncommenting line 7 makes the output 0. Why ??? VB.NET code: ** note the commented line, this is the culprit ** Dim xsl As New System.Xml.Xsl.XslTransform() Dim xw As New System.IO.StringWriter() Dim xmldoc As New System.Xml.XmlDocument() Dim xsldoc As New System.Xml.XmlDocument() xmldoc.Load("test.xml")
2
1510
by: Yogi21 | last post by:
Hi I have a sorted array containing strings. I am iterating through the array and clearing the contents one by one using "array.BinarySearch" to find each element. So far so good. But the moment I come to the last element, the BinarySearch method fails.It gives me a return value which is negative although the element is very much there. I am debugging through the code and I find nothing wrong with it.Note that i am using the first overloaded...
6
17075
by: Kenneth Moss | last post by:
I have a web service I am calling which I made. I am consuming this service from another domain (and I've tried from a windows app also). I added a certificate to the web service so it will use ssl. I made a web reference to the unsecured and secured version of the web service. When connecting unsecured, it works fine. When I connect secured I get this error: The underlying connection was closed: Could not establish trust...
20
7018
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt = document.getElementById('hometab'); Has anyone ever seen anything like this before, or am I dreaming?
3
1481
by: Christof Nordiek | last post by:
Hi, i have a setup project, wich is configured so that new versions will automatically uninstall in older version. It all works fine, but the installation fails, if the user selects another application directory than for the existing version. Gives twice a message that a part of a directory is missing. Then everything is rolled back. Maybe the problem is linked with an installer class i use in my project.
0
846
by: Chris | last post by:
I have an XMLdocument which I keep in cache which I use on my page. I use this function (in a separate dll) to read it from the cache and then read it from file if the cache is empty. This seems to work 99.9% of the time. But every couple of days or so the app throws an 'Object reference not set to an instance of an object.' on the getElementByTagName line below. Can anyone help on what would cause this problem. And any recomendations how...
5
7122
by: vinay550783 | last post by:
I have developed a web application which uses ajax to display some result in a div. Now this result works fine in explorer in xp or vista, but this when I run this page in windows CE IE 6.0 (ipilot 8000) this result is not displayed in the div, although when I alert the xmlHttp.responseText the result is showing there but not in the div. i am using the code document.getElementById('divid').innerHTML=xmlHttp.responseText; to display...
0
9705
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
9576
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
10074
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
9138
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7613
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6847
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5516
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4292
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
3
2988
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.