Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

safari picture .src

 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a line like this in my javascript programming.
myPict.src="pict.gif";
but for some reason, although it works fine in internet explorer, it does not work in Safari on my computer. My Safari browser seems to be following all the other javascript commands. Also when the page loads, the page has this HTML:
<img name="myPict" src="firstPict.gif">
and that works okay, that is, firstPict is visible.
What could be wrong? How about Firefox? Would it work in Firefox?
 
Jack Ploeg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I Think you could try to use the image's id, instead of it's name:

 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Indeed, name is not a valid attribute for the <image> tag.

As for Firefox, the best way to know is to try it.

Another tip: IE does so many things wrong that it's often easier to develop script in real browsers such as Safari or Firefox, and then port the JavaScript to IE rather than the other way around.
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I have now is something like this:

function drg(nw, fr, t, pc, nm){
window.status="entereddrg";
// more code
document.getElementById(pc).src="pict.gif";
}

<SELECT NAME="M28B1" SIZE="5" onchange="drg(M28B1.options[M28B1.selectedIndex].text, 24, 25, 'P28B1', 6)">
<OPTION>a</OPTION>
<OPTION>b</OPTION>
<OPTION>c</OPTION>
<OPTION>d</OPTION>
<OPTION>e</OPTION>
</SELECT>

<IMG ID="P28B1" SRC="firstpict.gif">

When I select an option, the window.status does not show anything, so it seems that the function drg is not even being called. Why could that be?
 
Jack Ploeg
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think this generates an error, because there is no element with id M28B1. Try giving your select this id:

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to reference elements by document.getElementById or document.formName.elementName. You CAN NOT just use their id, some browsers it works, but do not rely on that.

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use code tags when posting code to the forums. Unformatted code is extremely hard to read and many people that might be able to help you will just move along to posts that are easier to read. Please read this for more information.

You can go back and change your post to add code tags by clicking the button on your post.
 
Kevin Tysen
Ranch Hand
Posts: 255
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help, everyone. I followed the advice and things work fine. Also, I picked up on something that no one else seemed to notice. I noticed that Safari did not even run the function drg, and as soon as I changed the name of the function to xxx, Safari ran it. So I wonder if drg is a reserved word that means something to Safari and you can't use it to name a function.
Maybe it means 'degree' or 'drag' or something like that.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
drg is not a servered word.

Do you have an element on the page named drg or an element named drg? SOmetimes certain browsers flood the global namespace with them.
Eric
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic