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

saturationAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vibrazyCommented:
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
0
vibrazyCommented:
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
0
saturationAuthor Commented:
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.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

saturationAuthor Commented:
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...
0
saturationAuthor Commented:
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...
0
hieloCommented:
try:
function getData() {
      var myObject = document.getElementsByTagName("img")[1].nextSibling;
	 alert(myObject.nodeValue);
	 /*
      var x = [];
 
      sVal = document.getElementById("_Dataoppo_primarypersonid").nextSibling;
 
      for (var item in myObject) {
            x.push(item + ": " + myObject[item]);
      }
 
      alert(x.join("\n"));
	 */
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.