473,473 Members | 3,363 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Guidance Request (and a specific question)

I am wondering if JavaScript is a reasonable way to solve my problem. I
have to snatch some info from a web page and build a report. Some of the
info comes from the web page and some will be supplied by the end user.
This process will be initiated by the end user clicking on a menu item in
the IE (6.0) Tools menu. I will need to access the html of the web page and
then solicit some input from the end user via some form or something
similar. I know that's rather vague but does it seem feasible?

Thus far I am trying to access the html of the page and it's been tough
going. One of the bits of info I want to snatch from a web page is a
telephone number, which, on one of the web sites, looks like this ...

<table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td align='center' class='class_20' >Telphone: <span class='class_23'
style="font-size:14px;font-weight:bold;">111-222-3333</span></td>
</tr>
</table>

After reading the first few chapters in a JavaScript book and looking at
some DOM reference material, I've, so far, got the following:

<script type="text/javascript">
var parentwin = external.menuArguments;
var doc = parentwin.document;
var x = doc.getElementsByTagName("td")
alert(x.length + " td things")
// alert(x[0].toString)
for (whatever in x)
{ alert(whatever.nodeName)
}
</script>

I've tried many, many things but I have been unable to find the text I am
after - in this case "Telephone:" and the telephone number, "111-222-3333".
The objects returned by getElementsByTagName don't seem to have a toString
method, which I had hoped would give me "<td ... </td>". I am currently
trying to learn something about DOM "nodes" - but I am not at all sure that
that will be the answer. So, the specific question I promised - how do I
grab the strings "Telephone:" and "111-222-3333" from the html shown above.

Thanks for whatever help, pointers, sympathy you are kind enough to provide.
Bob

Jun 27 '08 #1
2 942
eBob.com wrote:
<table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td align='center' class='class_20' >Telphone: <span class='class_23'
style="font-size:14px;font-weight:bold;">111-222-3333</span></td>
</tr>
</table>

After reading the first few chapters in a JavaScript book and looking at
some DOM reference material, I've, so far, got the following:

<script type="text/javascript">
var parentwin = external.menuArguments;
var doc = parentwin.document;
I've tried many, many things but I have been unable to find the text I am
after - in this case "Telephone:" and the telephone number, "111-222-3333".
The objects returned by getElementsByTagName don't seem to have a toString
method, which I had hoped would give me "<td ... </td>".
With IE's HTML DOM the element nodes have properties innerText,
innerHTML and outerHTML. Also table elements objects have a rows
collection and rows have a cells collection. That way
var table1 = doc.getElementsByTagName('table')[0];
var cell1 = table1.rows[0].cells[0];
var text = cell1.innerText;
That cell above has a couple of child nodes, its firstChild is a text
node with the text "Telphone: ", its second child is a span element so
you could use
var text1 = cell1.firstChild.nodeValue;
and
var text2 = cell1.childNodes[1].innerText;
to have text1 hold the text "Telphone: " and text2 hold the text
"111-222-3333"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 27 '08 #2

"Martin Honnen" <ma*******@yahoo.dewrote in message
news:48**********************@newsspool1.arcor-online.net...
eBob.com wrote:
><table cellpadding='0' cellspacing='0' align='center'>
<tr>
<td align='center' class='class_20' >Telphone: <span class='class_23'
style="font-size:14px;font-weight:bold;">111-222-3333</span></td>
</tr>
</table>

After reading the first few chapters in a JavaScript book and looking at
some DOM reference material, I've, so far, got the following:

<script type="text/javascript">
var parentwin = external.menuArguments;
var doc = parentwin.document;

>I've tried many, many things but I have been unable to find the text I am
after - in this case "Telephone:" and the telephone number,
"111-222-3333". The objects returned by getElementsByTagName don't seem
to have a toString method, which I had hoped would give me "<td ...
</td>".

With IE's HTML DOM the element nodes have properties innerText, innerHTML
and outerHTML. Also table elements objects have a rows collection and rows
have a cells collection. That way
var table1 = doc.getElementsByTagName('table')[0];
var cell1 = table1.rows[0].cells[0];
var text = cell1.innerText;
That cell above has a couple of child nodes, its firstChild is a text node
with the text "Telphone: ", its second child is a span element so you
could use
var text1 = cell1.firstChild.nodeValue;
and
var text2 = cell1.childNodes[1].innerText;
to have text1 hold the text "Telphone: " and text2 hold the text
"111-222-3333"

--

Martin Honnen
http://JavaScript.FAQTs.com/
Thank you VERY much Martin! That's exactly what I needed. Bob
Jun 27 '08 #3

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

Similar topics

19
by: golson | last post by:
I have written a C function to copy a flash write routine that is in Flash memory to RAM memory. I have then created a function that uses a Function Pointer to run the copied function in RAM. ...
1
by: cylin | last post by:
Dear all, I am a newbie using lex and yacc. I really don't know what's wrong with my code, because the output is not what I want. My yacc rules don't match, and yylex seems just read only one...
1
by: Klaus Vestergaard Kragelund | last post by:
Hi there I cannot seem to get this to work. In LabWindows I want to be able to call the Sleep function. But when I #Include "Windows.h" I get errors that it cannot build: "Redeclearation of...
3
by: mrhicks | last post by:
Hello all, I have a question regarding efficeny and how to find the best approach when trying to find flag with in a structure of bit fields. I have several structures which look similar to ...
11
by: Ken Durden | last post by:
I am in search of a comprehensive methodology of using these two object cleanup approaches to get rid of a number of bugs, unpleasantries, and cleanup-ordering issues we currently have in our...
2
by: Robert Hanson | last post by:
I am new to the asp.net application building and I have read the information regarding the storing of information using session vs cookies vs viewstate. I am asking for suggestions/guidance as to...
3
by: ExclusiveResorts | last post by:
Can the CallContext be used reliably for storing request specific data? We are developing an application library that uses the CallContext to keep an IdentityMap (hashtable of business objects...
4
by: Nalaka | last post by:
Hi, I have some request specific data that gets created in a "early event", that I need to pass around to many other events. I need access to this data during that request. (and more importantly...
5
by: Realtime | last post by:
How do I go about writing a php application that will alert people in a database from different RSS news feeds from different sites. So lets say we have a database and user A has a list of news...
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
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...
1
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...
0
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...
0
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,...
1
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...
0
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...
0
muto222
php
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.