Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1000
  • Last Modified:

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

0
saturation
Asked:
saturation
  • 3
  • 2
1 Solution
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now