HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 27th, 2004, 06:47 PM
meatwad meatwad is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: who wants to know?
Posts: 32 meatwad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 36 sec
Reputation Power: 9
Checking to see if an image URL exists (JavaScript)

Wondering if this is possible. I've seen a couple of topics on this forum relating to a similar process checking for website URLs, I just thought this might be different enough to warrant a new approach.

Here's my code:

Code:
<script>

function validate()
{
x=document.myForm
mov=x.myInput.value
scene=x.myOptions.value

 if (scene=="blank")
  {
   document.forms[0].reset();
   document.forms[0].elements[0].blur();
   return;
  }

 if (mov=="blank")
  {
   document.forms[0].reset();
   document.forms[0].elements[0].blur();
   return;
  }

 document.getElementById('imag').src=x.myOptions.value + x.myInput.value

}

</script>


<form name="myForm">

Search for Images :: 
	<select name="myInput" size="1">

            <option selected value="blank">-- Movie Index --</option>
	    <option value="_Mov_1.JPG">First Movie
	    <option value="_Mov_2.JPG">Second Movie
	    <option value="_Mov_3.JPG">Third Movie
	    <option value="_Mov_4.JPG">Fourth Movie

	</select> 

	<select name="myOptions" size="1" onchange="validate()">

            <option selected value="blank">-- Scene Index --</option>
	    <option value="Scene_One">Scene One
	    <option value="Scene_Two">Scene Two
	    <option value="Scene_Three">Scene Three
	    <option value="Scene_Four">Scene Four
	    <option value="Scene_Five">Scene Five
	    <option value="Scene_Six">Scene Six
	    <option value="Scene_Seven">Scene Seven

	</select> 
</form>

<img id="imag" src="splash.JPG">



What I want to do is check and see if there is actually an image called, for example, "Scene_One_Mov_1", and if there isn't redirect the user to an error message. Would probably be written in an "if ... else" statement.

Thank you for your time

Meatwad

Reply With Quote
  #2  
Old August 27th, 2004, 06:52 PM
obi_wonton's Avatar
obi_wonton obi_wonton is offline
(not) Banned
Dev Shed Novice (500 - 999 posts)
 
Join Date: Apr 2004
Location: Toronto, CANADA
Posts: 598 obi_wonton User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 h 4 m 13 sec
Reputation Power: 10
Hmm... sorry, not about to go through all that mess. Here's one way to get it done:

Code:
<img src='invalid_url.png' onerror="alert('image does not exist/you are not connected to the internet');"


If you were to use a form to gather the urls to check, and then use a function to change the url of a 1x1 pixel image. If there was a problem, the onerror event would be triggered, and you can execute whatever code you want.
__________________
May the source be with you - obi_wonton

Last edited by obi_wonton : August 27th, 2004 at 06:54 PM.

Reply With Quote
  #3  
Old August 27th, 2004, 08:10 PM
meatwad meatwad is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2004
Location: who wants to know?
Posts: 32 meatwad User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 10 m 36 sec
Reputation Power: 9
shweet.

Quote:
Originally Posted by obi_wonton
Hmm... sorry, not about to go through all that mess. Here's one way to get it done:

Code:
<img src='invalid_url.png' onerror="alert('image does not exist/you are not connected to the internet');"


If you were to use a form to gather the urls to check, and then use a function to change the url of a 1x1 pixel image. If there was a problem, the onerror event would be triggered, and you can execute whatever code you want.



Perfect fit! Thank you.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > Checking to see if an image URL exists (JavaScript)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap