GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes safari picture .src Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "safari picture .src" Watch "safari picture .src" New topic
Author

safari picture .src

Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
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

Joined: Jan 08, 2010
Posts: 5
I Think you could try to use the image's id, instead of it's name:

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61309
    
  66

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kevin Tysen
Ranch Hand

Joined: Oct 12, 2005
Posts: 255
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

Joined: Jan 08, 2010
Posts: 5
I think this generates an error, because there is no element with id M28B1. Try giving your select this id:

Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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

Joined: Jan 10, 2002
Posts: 61309
    
  66

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

Joined: Oct 12, 2005
Posts: 255
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

Joined: Nov 08, 2001
Posts: 15376
    
    6
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
 
wood burning stoves
 
subject: safari picture .src