la*******@gmail.com wrote:
For the <P> tag I can use OMON_3.innerText,
If IE is the only browser to be exposed to this script, then yes you can.
However, in my application depending on how the page is viewed,
either the <P> tag will be displayed or <Input>. Is there a way to
find the value in both cases with the same piece of code?
Once you have a reference to an element, you can determine the type of
element using either the tagName (for HTML documents) or nodeName (for
either XML-based or HTML documents) properties.
However, you're going to have difficultly getting that reference at
all with the mark-up you've posted: the P element can be obtained
using the getElementById method, however the INPUT element doesn't
have an id so it can't[1]. Generate an id attribute for both elements
and you can use something like:
var e = document.getElementById('OMON_3'),
v = '';
if(e) {
if(('P' == e.tagName) && e.firstChild) {
v = e.firstChild.data;
} else if('INPUT' == e.tagName) {
v = e.value;
}
}
[snip]
<INPUT style="width:135px" maxlength="15" name="OMON_3"
tabindex="4" value="TEST" />
For an XML-based document, the strings used to compare tag names will
need to be lowercase, and the property changed from tagName to
nodeName. That said, despite the XHTML-like syntax used above, you
clearly aren't using XHTML as HTML-adopted tag names must be
lowercase. Remove the forward slash (/) from the end of the tag.
Hope that helps,
Mike
[1] The behaviour exhibited by IE where getElementById will retrieve
an element reference by either id or name is erroneous and it
should not be relied upon. Whichever Microsoft decision maker
thought that one up is an idiot!
--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.