href changing depending on what image

Discussion in 'JavaScript' started by vin_akleh, Oct 18, 2010.

  1. #1
    hello
    i have this code that tags between three images in an certain amount of time
    and this works fine
    <script language = "Javascript">
    <?php $count_im=1;
     $req=mysql_query("select * from banner");
    	while ($res=mysql_fetch_array($req)){ ?>
    var image<?php echo $count_im; ?> =new Image()
    image<?php echo $count_im; ?>.src="<?php echo $res["banner"]; ?>"
    <?php $count_im++;
    }?>
    </script>
    HTML:
    <div class="banner">
    	<p class="banner_image">
    		<img src="banner/12.jpg" name="slide" width="290px">
    		<script>
    			<!--
    			//variable that will increment through the images
    			var step=1
    			function slideit(){
    			//if browser does not support the image object, exit.
    			if (!document.images)
    			return
    			document.images.slide.src=eval("image"+step+".src")
    			if (step<3)
    			step++
    			else
    			step=1
    			//call function "slideit()" every ... seconds
    			setTimeout("slideit()",10000)
    			}
    			slideit()
    			//-->
    		</script>
    	</p>
    </div>
    HTML:
    and i want it also to tag between hrefs too, so tried the following but didnt work
    <?php $count_im=1;
     $req=mysql_query("select * from banner");
    	while ($res=mysql_fetch_array($req)){ ?>
    var image<?php echo $count_im; ?> =new Image()
    image<?php echo $count_im; ?>.src="<?php echo $res["banner"]; ?>"
    
    var link<?php echo $count_im; ?> =new String()
    link<?php echo $count_im; ?>.href="<?php echo $res["banner_title"]; ?>"
    
    <?php $count_im++;
    }?>
    HTML:
    <div class="banner">
    	<p class="banner_image">
    		<a href="" target="_blank" name="links">
    		<img src="banner/12.12" name="slide" width="290px"></a>
    		<script>
    			<!--
    			//variable that will increment through the images
    			var step=1
    			function slideit(){
    			//if browser does not support the image object, exit.
    			if (!document.images)
    			return
    			document.images.slide.src=eval("image"+step+".src")
    			document.a.links.href=eval("link"+step+".src")
    			if (step<3)
    			step++
    			else
    			step=1
    			//call function "slideit()" every ... seconds
    			setTimeout("slideit()",10000)
    			}
    			slideit()
    			//-->
    		</script>
    	</p>
    </div>
    HTML:
    anyone can help???
     
    vin_akleh, Oct 18, 2010 IP
  2. kai555

    kai555 Peon

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi

    instead of using document.a.links.href= try giving your link an id:
    <a href="" target="_blank" name="links" id="thelink">

    and then use:
    document.getElementById('thelink').href=
     
    kai555, Oct 21, 2010 IP