473,796 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IE7 javascript using DOM wont output Dynamic Text?

hoist1138
6 New Member
Thanks to anyone who may be able to steer me in the right direction :)

Interesting that this works fine in All Browsers BUT Internet Explorer.
fairly simple goal......

get a "src" img element attribute and display it (by manipulating DOM elements) on the webpage under a graphic...(for a dynamic label)

Expand|Select|Wrap|Line Numbers
  1. var mainPic = document.getElementById("placeholder");
  2.  
  3. var picSrc = mainPic.getAttribute("src");
  4.  
  5. var container = document.getElementById("divContainer");//the container div refference so I can use replaceChild() method to replace the targeted <p> Child Node
  6.  
  7. var oldText = document.getElementById("replaceMe");
  8. var newPara = document.createElement("p");
  9. var lableName = document.createTextNode(picSrc); //this variable doesnt want to transfer in IE, works fine in FF and Safari
  10. newPara.appendChild(newName);
  11. newPara.setAttribute("id","replaceMe");
  12.  
  13. container.replaceChild(newPara,oldText);
again, the goal is satisfied if all I can do is get IE to actually out put a dynamic text variable using the DOM with replaceChild()
Is there a known issue with outputing strings using the DOM in IEx?
thanks to all who lend some brain matter.
Jan 8 '08 #1
10 2647
mrhoo
428 Contributor
newPara.appendC hild(newName);
You have no variable newName declared.
Jan 8 '08 #2
hoist1138
6 New Member
opps, thanks for the look...I forgot to include it in the Original post, Again heres the weird thing, It works great in all other browsers, and I have tried to look google over and over. Im not sure where to look for this issue.

Expand|Select|Wrap|Line Numbers
  1. var mainPic = document.getElementById("placeholder");
  2.  
  3. var picSrc = mainPic.getAttribute("src");
  4.  
  5. var container = document.getElementById("divContainer");//the container div refference so I can use replaceChild() method to replace the targeted <p> Child Node
  6.  
  7. var oldText = document.getElementById("replaceMe");
  8.  
  9. var newPara = document.createElement("p");
  10.  
  11. var lableName = document.createTextNode(picSrc); //this variable doesnt want to transfer in IE, works fine in FF and Safari
  12. var newName = picSrc;
  13. newPara.appendChild(newName);
  14.  
  15. newPara.setAttribute("id","replaceMe");
  16.  
  17. container.replaceChild(newPara,oldText);
Jan 8 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
What's the value of the src attribute? Is it relative or an absolute path?
Jan 9 '08 #4
hoist1138
6 New Member
here is an example of an image name that the script gets and displays on the page perfectly fine with FF and safari..

Expand|Select|Wrap|Line Numbers
  1. //heres the HTML the image src attrib I want to grab....
  2. <img src="Single/VG-001B.jpg" alt="" name="placeholder" width="450" height="350" id="placeholder" />
  3.  
  4. //heres the javascript targeting that src attrib......
  5.  
  6. var mainPic = document.getElementById("placeholder");
  7. //set up the PARENT DIV CONTAINER so the child elements can be manipulated
  8. //first check if the current pages has the <div id="divContainer"> node there, otherwise forget this section!
  9.         if(document.getElementById("divContainer")){
  10. var picSrc = mainPic.getAttribute("src");
  11.             var getFullName = picSrc.split("/");//use the "/" character to mark the split point into an array
  12.             var getName = getFullName[1].split(".");
  13.             var finalName = getName[0];
  14.             var container = document.getElementById("divContainer");
  15.             var oldText = document.getElementById("replaceMe");
  16.             var newPara = document.createElement("p");
  17.             var newName = document.createTextNode(finalName);
  18.             /*var test = document.createTextElement("this is a test");*/
  19.             /*var myText = document.getElementById("text");*/
  20.             newPara.appendChild(newName);
  21.             newPara.setAttribute("id","replaceMe");
  22.             container.replaceChild(newPara,oldText);
  23.             }
  24.  
  25.             //stop the default a link behavior
  26.             return false;
  27.  
its an absolute path right?
Jan 10 '08 #5
hoist1138
6 New Member
by the way to see the real world example for my client.....
http://www.pet-memorial-markers.com/...owerVases.html
the vase name at the bottom of the graphic is the graphic name extracted from the path
again, try it in FF or Safari, and then.......IE and BLAM, no dynamic src attribute rendering to the page.....

one solution I was thinking of was doing detection script for IE, heres the prototype.....

if ( IE ){
then use non-standard INNER HTML to render to the browser
}else{
use standards like the DOM because standards make life easier for humans that build stuff
}
Jan 10 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
If you alert picSrc, you will see that IE converts it to a full path, while the rest of the browsers leave it as you expect it to be.
Jan 11 '08 #7
Romulo NF
54 New Member
If i got it right thats more or less what you need

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2.  
  3. <html>
  4. <head>
  5.     <title>Dinamic Label</title>
  6. </head>
  7.  
  8. <script>
  9.  
  10. window.onload = function() {
  11. imgs = document.getElementsByTagName("img")
  12. images = new Array()
  13.  
  14.     for (x=0; x<imgs.length; x++) {
  15.     images[x] = new createDynamicLabel(imgs[x])
  16.     }
  17. }
  18.  
  19. function createDynamicLabel(imgReference) {
  20. this.image = imgReference
  21.  
  22. this.name = this.image.src.substring(this.image.src.lastIndexOf("/")+1,this.image.src.lastIndexOf("."))
  23.  
  24. this.lineBreak = document.createElement("br")
  25. this.image.parentNode.insertBefore(this.lineBreak,this.image.nextSibling)
  26.  
  27. this.label = document.createElement("em")
  28. this.label.innerHTML = this.name
  29. this.label.style.textTransform = "capitalize"
  30. this.label.style.font = "bold 11px verdana"
  31.  
  32. this.image.parentNode.insertBefore(this.label,this.lineBreak.nextSibling)
  33. }
  34.  
  35. </script>
  36.  
  37. <body>
  38.  
  39. <img src="down.gif">
  40.  
  41. <br><br>
  42.  
  43. <img src="aceitar.gif">
  44.  
  45. <br><br>
  46.  
  47. <img src="add.gif">
  48.  
  49. <br><br>
  50.  
  51. <img src="cancelar.gif">
  52.  
  53. </body>
  54. </html>
  55.  
  56.  
Good luck!

ps: take care with additional blank spaces in the code like in line 32
Jan 11 '08 #8
acoder
16,027 Recognized Expert Moderator MVP
If i got it right thats more or less what you need
Nice! That should do the trick - the most important thing is the use of lastIndexOf().
Jan 11 '08 #9
hoist1138
6 New Member
thanks everyone, all masters...
Jan 14 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
4832
by: Satish.Talyan | last post by:
hi, i want to create a dynamic tree hierarchy in javascript.there are two parts in tree, group & user.when we click on group then users come under that's tree category will be opened.problem is that i am not able to arrange three things simultaneously,group,users & there functionality simultaneously.dynamic means group & users come from database and groups & users can be increased in number at any time. i am sending code for that tree...
11
2788
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from doing this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
11
1418
by: Nathan Sokalski | last post by:
I add several JavaScript events (onchange, onkeypress, etc.) to Controls using the Add method of the Attributes collection. However, if the JavaScript code contains certain characters, such as & or < or several others, it converts them to html, such as &amp; or &lt; which can sometimes cause my scripts not to work. How can I prevent ASP.NET from doing this? Thanks. -- Nathan Sokalski njsokalski@hotmail.com http://www.nathansokalski.com/
1
108779
Frinavale
by: Frinavale | last post by:
Introduction I've seen many questions asked about how to disable the browser's back button and in the past I've replied with "it's simply not possible". It's not a good idea to disable the back button anyways, if the user ventures away from your page then they wouldn't have this button at their disposal. The main reason people ask how to control or disable the back button is because they have a need to control sensitive (and/or) dynamic web...
0
9528
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10455
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10228
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10006
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7547
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6788
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5441
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5573
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3731
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.