Accessing an Unnamed HTML element

D

DrKen

I want to access a value that is hidden on the HTML page but it
doesn't look like a standard element.
<!-- Primary_Last_Nm -->
<div id="field-lastnamehidden">
<span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
</div>

The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />

causes a database to be accessed in the specific environment I'm
working in. However, it still in the end has to be meaningful HTML.
So I'm wondering if there is some way to access this item, even though
I see no way to attach a name to it. Thanks.

Ken
 
T

Tom de Neef

DrKen said:
I want to access a value that is hidden on the HTML page but it
doesn't look like a standard element.
<!-- Primary_Last_Nm -->
<div id="field-lastnamehidden">
<span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
</div>

The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />

causes a database to be accessed in the specific environment I'm
working in. However, it still in the end has to be meaningful HTML.
So I'm wondering if there is some way to access this item, even though
I see no way to attach a name to it. Thanks.

Maybe use a hidden element, along the lines of:
<p><span style="visibility:hidden">pstag:profile
value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text"</span>Click here to access db</p>

Tom
 
D

Denis McMahon

I want to access a value that is hidden on the HTML page but it doesn't
look like a standard element. <!-- Primary_Last_Nm -->
<div id="field-lastnamehidden">
<span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
</div>
The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />
causes a database to be accessed in the specific environment I'm working
in. However, it still in the end has to be meaningful HTML. So I'm
wondering if there is some way to access this item, even though I see no
way to attach a name to it. Thanks.

This isn't markup in the sense of markup that gets delivered to the
browser, it's a processing directive to some server side application.

What actually appears in the document that the web browser receives is
probably whatever output the other application is generating.

The database query could be generating any amount of non block level html
(if it generates any block level markup, I think the fact it's enclosed
in a span may break things).

The best way to see what appears is to view source in a browser when
looking at the actual output from the server process, rather than the
source file. Then you will see the context that your javascript is
actually working in.

I thought this had been explained to you previously. Are you failing to
read the explanations you are being given, failing to comprehend them, or
just ignoring anything which doesn't agree with some preset world view
that can't absorb that "the file on the server isn't actually the web
page that arrives at the client's browser".

Rgds

Denis McMahon
 
D

DrKen

This isn't markup in the sense of markup that gets delivered to the
browser, it's a processing directive to some server side application.

What actually appears in the document that the web browser receives is
probably whatever output the other application is generating.

The database query could be generating any amount of non block level html
(if it generates any block level markup, I think the fact it's enclosed
in a span may break things).

The best way to see what appears is to view source in a browser when
looking at the actual output from the server process, rather than the
source file. Then you will see the context that your javascript is
actually working in.

I thought this had been explained to you previously. Are you failing to
read the explanations you are being given, failing to comprehend them, or
just ignoring anything which doesn't agree with some preset world view
that can't absorb that "the file on the server isn't actually the web
page that arrives at the client's browser".

Rgds

Denis McMahon

None of the above. I am aware that the PSTAG bit is processed on the
server, and based upon my own experimentation, processed after the
page has completing loading. So what I have is essentialy a SPAN tag,
a database value, and a SPAN end tag. That's not the sort of HTML I"m
used to. Without other tags, this would just be a string on the page,
and the usefulness of that seems questionable to me. Least wise, in
other web technologies, it would be. I wouldn't write a JSP to try to
grab or process in any way a simple string on a web page. I tried
looking at the source of the page when I only brought up the page, but
that didn't help. I'm working on seeing what gets generated in
reality but it's difficult in the environment I am in (PS CRM 9.0).
I've actually been trying most of the morning's to get Oracle's Dialog
Execution Server in CRM accept the new version I made of the page and
let me run the app. That hasn't worked so far (it's a CRM thing, not
an HTML or JavaScript thing). Thanks.


Ken
 
T

Thomas 'PointedEars' Lahn

Tom said:
Maybe use a hidden element, along the lines of:
<p><span style="visibility:hidden">pstag:profile
value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text"</span>Click here to access db</p>

Blind leading the blind …

The "specific environment" is very likely a server-side one that is
*generating* HTML *from* this _XML_ element (using data retrieved from the
server-side database). In that case the OP should look at the *client-side*
code, or find a way in their server-side code (perhaps an attribute of that
XML element; e. g., ASP-based server-side applications can use the `id'
attribute value of elements that also have runat="server" specified) to
refer to the generated element. (The latter is off-topic here.)

However, if this is actually client-side code, then it is _not_ HTML (but
perhaps XHTML), and the element object needs to be referred to using the XML
DOM, e. g.

document.getElementsByTagNameNS(namespaceURI, "pstag:profile")[0]

whereas `namespaceURI' must be a string value with the URI of the namespace
defined for the `pstag' prefix (look for `xmlns:pstag="…"'). The
possibility remains that the markup is further transformed with an XSL
stylesheet client-side (several UAs have XSLT processors built-in, which can
be used with and without DOM scripting), or replaced using the DOM, in which
case the element in the transformation result or replacement needs to be
referred. But it is unlikely.


PointedEars
 
R

RobG

I want to access a value that is hidden on the HTML page but it
doesn't look like a standard element.
<!-- Primary_Last_Nm -->
<div id="field-lastnamehidden">
<span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
</div>

The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />

causes a database to be accessed in the specific environment I'm
working in. However, it still in the end has to be meaningful HTML.
So I'm wondering if there is some way to access this item, even though
I see no way to attach a name to it. Thanks.

Ken

So it seems, from other responses, that you have a span inside an div
element with id of "field-lastnamehidden". You can get to the span
using:

var span;
var parentDiv = document.getElementById('field-lastnamehidden');
if (parentDiv) {
span = parentDiv.getElementsByTagName('span')[0];
}

In recent Gecko browsers (and perhaps others) there is also a children
collection[1].

You could iterate over the span elements looking for text content that
matched an expected pattern for the data. Without an explicit
reference to the element containing the data, you are really just
guessing.


1. <url: https://developer.mozilla.org/En/DOM/Element.children >
 
D

Denis McMahon

None of the above. I am aware that the PSTAG bit is processed on the
server, and based upon my own experimentation, processed after the page
has completing loading.

WRONG!

The server side processing MUST take place BEFORE the page is delivered
to the browser. That's the whole point of server side processing, you
include directives to the server side processor in amongst your html
markup, and the pre-processor that is invoked server side replaces those
directives with some content before handing the result to the server to
send across the internet to the browser.

If you are seeing the pstag element in the browser, then the server you
are using to serve the code is not handling the pstag element / doing the
server-side pre-processing properly.

<pstag:... is not a recognised element for any web browser.
So what I have is essentialy a SPAN tag, a
database value, and a SPAN end tag. That's not the sort of HTML I"m used
to.

IT! IS! NOT! HTML!

Not just some sort of html you're not used to, but NOT HTML AT ALL!

What you should have in the output from the server is the span tag
enclosing whatever markup was generated by the server side pre-processor
in response to the complete said:
Without other tags, this would just be a string on the page, and
the usefulness of that seems questionable to me. Least wise, in other
web technologies, it would be.

What it should actually be is some piece of content generated by the pre-
processor on the server that handles the <pstag:... directive.

<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />

I would guess from the parameters of the pstag directive that what is
meant to appear there is either someone's last name, or first and last
names, as text.

In other words, what should be delivered to the browser is probably
something like either:

<div id="field-lastnamehidden"><span class="value">McMahon</span></div>

or:

<div id="field-lastnamehidden"><span class="value">Denis McMahon</span></
div>

and given the id of the div, I'd go with the former - it's meant to be
someone's lastname!

You can probably refer to it in javascript with:

document.getElementById("field-lastnamehidden").firstChild.innerHTML;

Where:

document.getElementById("field-lastnamehidden") references the <div
id="field-lastnamehidden"> element.

document.getElementById("field-lastnamehidden").firstChild references the
<span> within that div.

document.getElementById("field-lastnamehidden").firstChild.innerHTML
references the content of that span.

But I'm still troubled that you don't seem to understand the sequences
that things happen in or comprehend the roles played by different
software components on the web server and client browser that are
involved in the process of converting the file on the server platform
hard disc to something displayed in a client browser window.

Broadly speaking, this is what happens when a web page is requested (and
yes, I know at least one poster will post a comment that I'm wrong,
without actually saying what part of the sequence I got wrong, and at
bleats one poster will probably post an incorrect correction, but it's
possible that some other poster will actually correct some
misunderstanding on my part):

1) Client browser requests url from web server
2) Web server converts the url into a file name (possibly with some
additional request parameters)
3) Webserver gets the file from wherever it's stored and either (a) sends
the file straight to the client browser as is, or (b) calls one or more
external program(s) by some means to process the file (and any additional
request parameters), and sends the eventual output of the program(s) to
the client browser.
4) The client browser renders the page, which includes processing any js
in the header, included js files or the page itself, as well as all
relevant css, subject to any constraints on css and js set in the client
browser.
5) The client browser executes any "onload" js subject to any constraints
on js etc per 4.
6) The page now reacts to the viewer filling in form fields, clicking
things etc.

The oracle crm in this scenario kicks in (or should do) at 3(b) in the
above 6-step description of how a web page loads. Javascript is not
executed until step 4 and onload events step 5. User action initiated
function code triggers at step 6 in response to user input.
I wouldn't write a JSP to try to grab or
process in any way a simple string on a web page. I tried looking at
the source of the page when I only brought up the page, but that didn't
help. I'm working on seeing what gets generated in reality but it's
difficult in the environment I am in (PS CRM 9.0).

As far as referring to the crm data in the generated output with
javascript, I've given you a method to do that. However, that's in the
generated output, not the source file!
I've actually been
trying most of the morning's to get Oracle's Dialog Execution Server in
CRM accept the new version I made of the page and let me run the app.
That hasn't worked so far (it's a CRM thing, not an HTML or JavaScript
thing).

If you are having issues with the oracle crm platform and the syntaxes
that apply to it, ask the oracle crm system helpdesk or in a forum or
newsgroup that's dedicated to that forum.

Rgds

Denis McMahon
 
D

Dr J R Stockton

In comp.lang.javascript message <074944f1-f4fe-4af0-9c35-32f5c4c0f537@y1
3g2000prb.googlegroups.com>, Mon, 11 Jul 2011 11:47:41, DrKen
I want to access a value that is hidden on the HTML page but it
doesn't look like a standard element.
<!-- Primary_Last_Nm -->
<div id="field-lastnamehidden">
<span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
</div>

The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />

causes a database to be accessed in the specific environment I'm
working in. However, it still in the end has to be meaningful HTML.
So I'm wondering if there is some way to access this item, even though
I see no way to attach a name to it. Thanks.


You can access the DIV by its ID. The SPAN should be its firstChild.
The PSTAG should be that's firstChild, or all of its children - or its
content in some other way.

For test, insert a copy of my
<http://www.merlyn.demon.co.uk/inc-prop.js> on your page in the usual
manner - a COPY, not using that URL - after reading
<http://www.merlyn.demon.co.uk/ijs-props.htm> and trying "The First
Form".

Or use whatever DOM-inspecting tools you already know.

Please read the newsgroup FAQ in tab-indenting, and the quote above to
see one reason why.
 
D

dhtml

  I want to access a value that is hidden on the HTML page but it
doesn't look like a standard element.
<!-- Primary_Last_Nm -->
                        <div id="field-lastnamehidden">
                                <span class="value"><pstag:profile value="Individuals.CS-Appl
Biographic.Primary_Last_Nm" poutput="Text" /></span>
                        </div>
The unusual part of this,
<pstag:profile value="Individuals.CS-ApplBiographic.Primary_Last_Nm"
poutput="Text" />
causes a database to be accessed in the specific environment I'm
working in.  However, it still in the end has to be meaningful HTML.
So I'm wondering if there is some way to access this item, even though
I see no way to attach a name to it.   Thanks.

So it seems, from other responses, that you have a span inside an div
element with id of "field-lastnamehidden". You can get to the span
using:

  var span;
  var parentDiv = document.getElementById('field-lastnamehidden');
  if (parentDiv) {
    span = parentDiv.getElementsByTagName('span')[0];
  }

In recent Gecko browsers (and perhaps others) there is also a children
collection[1].
That's an IE property that got codified. In IE, `children` is
historically a collection of "DHTML Objects" (what MS called it) and
included comment elements. Yep, you read right: Comment elements --
that's another MS term. Safari versions up to and maybe including
Safari 3 also had some anomalies with `children`.

Give SPAN an ID. Or use querySelector; that should be more reliable
than `children`.

divParent.querySelector("span");
You could iterate over the span elements looking for text content that
matched an expected pattern for the data. Without an explicit
reference to the element containing the data, you are really just
guessing.

+1 for giving the SPAN and ID.
 
D

dhtml

In comp.lang.javascript message <074944f1-f4fe-4af0-9c35-32f5c4c0f537@y1
3g2000prb.googlegroups.com>, Mon, 11 Jul 2011 11:47:41, DrKen
<[email protected]> posted:
Don't use fake tags -- fake namespacing when using HTML is just asking
for it. I'm surprised to see Google's +1 feature using this approach
in a public release for so long -- been a few weeks now.
You can access the DIV by its ID.  The SPAN should be its firstChild.
The PSTAG should be that's firstChild, or all of its children - or its
content in some other way.
Sure. Until somebody comes along and adds whitespace to the div, like
so:

<div id="field-lastnamehidden">
<span>pstag...</span>
</div>

Then the firstChild is going to be a Text node.
 
R

RobG

Don't use fake tags -- fake namespacing when using HTML is just asking
for it. I'm surprised to see Google's +1 feature using this approach
in a public release for so long -- been a few weeks now.



Sure. Until somebody comes along and adds whitespace to the div, like
so:

<div id="field-lastnamehidden">
  <span>pstag...</span>
</div>

Then the firstChild is going to be a Text node.

There is the firstElementChild property[1], but it might be a bit new
for some browsers. It seems to be a response to the issue you raise.

1. <http://www.w3.org/TR/ElementTraversal/#attribute-
firstElementChild>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top