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

href changing depending on what image

Status
Not open for further replies.

vin23akleh

Programmer
Mar 6, 2010
6
JO
hello
i have this code that tags between three images in an certain amount of time
and this works fine
Code:
<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>
Code:
<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>
and i want it also to tag between hrefs too, so tried the following but didnt work
Code:
<?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++;
}?>
Code:
<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>
anyone can help???
 
Please avoid posting server side code. Always post the resultant HTML source code from the View Source option in your browser as it makes it easier to debug if we know what the browser ends up seeing.

Don't quite get what you are attempting to do, but you are attempting to use a .src attribute in your loop, but your links only have an href attribute set.

Code:
var link<?php echo $count_im; ?> =new String()
link<?php echo $count_im; ?>.[red]href[/red]="<?php echo $res["banner_title"]; ?>"

...
 document.a.links.href=eval("link"+step+".[red]src[/red]")

Your attempt at accessing the link objects would create errors as there is no actual "a" object collection. perhaps what you want to use is the links collection. And assuming your link's name is "links":

Code:
 document.links['links'].href=eval("link"+step+".src")

However you'll see no visible change with that, since the link's text would remain the same . You may want to change that as well.


Code:
 document.links['links'].innerHTML="Some text you may want there";

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
this is the final solution
HTML:
<div class="banner">
	<p class="banner_image">
		<a href="" target="_blank" name="links">
		<img src="banner/blank.jpg" 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+".href")
			document.links['links'].href=eval("link"+step+".href")
			if (step< <?php echo $count_im-1; ?> )
			step++
			else
			step=1
			//call function "slideit()" every ... seconds
			setTimeout("slideit()",10000)
			}
			slideit()
			//-->
		</script>
	</p>
</div>
thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top