Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

safari picture .src

 
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?
 
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:

 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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:

 
author
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
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • 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
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
 
Stop it! You're embarassing me! And you are embarrassing this tiny ad!
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic