Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I check the img.src value for a certain value

Status
Not open for further replies.

weedz

Programmer
Dec 5, 2000
718
0
0
NL
Hi all,

I am quite new to javascript so please excuse me if this is a beginners question.

I need to check an images src value against a constant value.

Here is what I do in words:

I fill an array with paths to different images.
When a user click on an image, it will be replaced by a randomly chosen elemnt form the array and a new image will be displayed.
But, when the user click on this image again, I would like to reset it to the original constant value.

When I do something like:

If (document
.src != "mypathandImage.lpg")
{document
.src = "mypathandImage.lpg";
}
then I get an object required and the whole thing stops.

Any help would be much appreciated.

TIA,

DaWeedz

Weedz (Edward W.F. Veld)
 
Some questions which might help solve this:

- Where are you defining "imgname"?

- What does "imgname" contain at the time you are using it?

- Do your images have name attributes?

- Do any of those name attributes match the value held in the variable "imgname"?

- If so, when are you calling the script? Are you waiting for the page to load before doing so?

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I knew it was a beginners mistake. Thnx !.

Weedz (Edward W.F. Veld)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top