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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript image change 1

Status
Not open for further replies.

madhatt30

Technical User
Joined
Mar 30, 2005
Messages
5
Location
US
I have the javascript image refresh only down, but i'm trying to refresh a webcam image ever 5 sec but I need to be able to change the source for the other cams. For example I view my webcams for 3 hours during those 3 hours The webcams switch every hour on the hour. If the hour two comes along i'll be looking at an empty screen. Question is how do you get the document.images['cam'].src to relect the new directory for the cam. BTW each cam has to be in a different directory. I thought of checking a database to see if the location has changed and then go from there but i haven't found a way to do that in javascript yet. I'd also be open to scripts to perform this is there is a solution that way. Any help would be appreciated.
 

how are you changing the cameras each hour? if it's done using scripts, i would create a .txt file and each time the camera changes, just write to that text file a number corresponding to the camera.

then have in your javacript code a function that refreshes every 5 seconds...before each refresh, check that text file...the first time the refresh script occurs, set a variable equal to the number in the text file. then every subsequent refresh, just check the number stored in the variable against the number in the text file; if different, adjust src for web cam view accordingly.

how does that sound?

- g
 
Thank you that really is a good idea :). I have since spent the last 12 hours on this and have also found another way around as well. I may still use your idea though lol. I shall show the source here in case it helps someone else as well.

<script language="JavaScript">
var dat1;
var g_intervalID;
var lCmds;
function refreshIt() {
<?php echo getUserImage(); ?>; //execute php function
dat1="<?php echo $imgpath; ?>"; //Set variable from php function
var room_image ="<?php echo $_POST["room_name"]; ?>";
if (!document.images) return;
document.images['cam'].src=dat1;
setTimeout('refreshIt()',5000); // refresh every 5 secs //-->
}
</script>
<script language="php">
function getUserImage()
{
global $imgpath;
// Insert script to access database and see who is logged in
$imgpath=" . "[insert dir and image name here";
// $imgpath = "./livepsychic1/cam.jpg";
}
</script>

Now there are a few things that I couldn't include for privace reasons :). Also note that this is in a .php file
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top