Link to home
Start Free TrialLog in
Avatar of saturation
saturation

asked on

Get innerText next to img tag

The following Javascript will do an alert of all the elements in the object, but I need it to specifically do an alert box with the phone number inside the code below ("222 333 4444").  There is always an img tag using the icon "SmallPhone.gif" to the left of the number, and I need to just get the innerHTML in between that tag and the next one and do the alert box.   How can I do this?
<html>
<script>
 
window.attachEvent("onload",getData);
 
function getData() {
	var myObject = document.getElementsByTagName("img")[0].nextSibling;
	var x = [];
 
	sVal = document.getElementById("_Dataoppo_primarypersonid").nextSibling;
 
	for (var item in myObject) {
		x.push(item + ": " + myObject[item]);
	}
 
	alert(x.join("\n"));
}
 
</script>
 
<body >
 
<SPAN ID=_Dataoppo_primarypersonid class=VIEWBOX >
 
<IMG SRC="/CRM61/img/Icons/test.gif" HSPACE=0 BORDER=0 ALIGN=TOP HEIGHT=16>
<A HREF="/CRM61/eware.dll/Do?SID=10739501843508&Act=220&Mode=1&CLk=T&Key0=2&Key2=13&Key7=14&Key27=10158&Key50=19">ssdf sdf</A>&nbsp;
<IMG SRC="/CRM61/img/Icons/SmallPhone.gif" HSPACE=0 BORDER=0 ALIGN=TOP HEIGHT=16>
&nbsp;222 333 4444
<input type=hidden name=_HIDDENoppo_primarypersonid value="13">
<input type="hidden" name="_HIDDENSearchFieldoppo_primarypersonid" id="_HIDDENSearchFieldoppo_primarypersonid" value="oppo_primarypersonid">
 
</SPAN>
</body>
</html>

Open in new window

Avatar of vibrazy
vibrazy
Flag of United Kingdom of Great Britain and Northern Ireland image

I would wrap the tel number in a span element with an id of tel.
<span id="tel"></span>

Then
var tel = document.getElementById('tel');
alert(tel.innerHtml);

Try that
As it stands the telephone number is floating, its not contained in any elements apart from the
<SPAN ID=_Dataoppo_primarypersonid class=VIEWBOX >

So i would create its own container

Regards,
Dan
Avatar of saturation
saturation

ASKER

Unfortunately, I don't have control over that portion of the page--I have to do with what is already there and figure out a way to get it from DHTML/Javascript in between <script> tags.
I basically need to get the text in between the "SmallPhone.gif" img tag and the next tag which is the "_HIDDENSearchFieldoppo_primarypersonid" but I'm not sure how to do this...It will always be between these two tags...
I meant that I basically need to get the text in between the "SmallPhone.gif" img tag and the next tag which is the "_HIDDENoppo_primarypersonid" but I'm not sure how to do this...It will always be between these two tags...
ASKER CERTIFIED SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial