Forum Moderators: open

Message Too Old, No Replies

can't find the mistake/ js switching image and link

         

wonderer

10:48 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



this is the code i have

-------------------------------------
<?php

$path // path
$url // each image has a link to a page (with the same ID of the image)
$totimg // size of arrays
$stationID // array of values
$stationNM // array of option names
$size // width & height of images

?>

<SCRIPT LANGUAGE="JavaScript1.2">

function uSlct (ImgID, position)
{
document.locality.weatherID.options.selectedIndex = position;
replaceImage(ImgID);
// chbutton(document.locality.weatherID);
}

function replaceImage(ImgID)
{
document.weatherImg.src = '<? echo"$path";?>'+ImgID+'.gif';
}

</SCRIPT>

<script language="Javascript" type="text/javascript">
var imgArr = new Array();
<?php
$i = 0; // initalize counter for js array index
foreach($stationID as $val)
{
echo 'imgArr[' . $i . '] = ' . $val . ';';
$i++;
}
?>
</script>

<table width='100%' cellpadding='0' cellspacing='0'><tr><td colspan='2' align='center'>

<?
echo "<a href='$url$stationID[0].html' target='_blank' onClick=\"this.href='$url'+imgArr[document.forms[0].weatherID.selectedIndex]+'.html'\">";
echo "<img name='weatherImg' src='$path$stationID[0].gif' alt='$label' $size /></a>";
?>

<FORM NAME="locality" METHOD="POST" >
<SELECT NAME="weatherID" onchange="replaceImage(this.options[this.selectedIndex].value);" class="button" style="width:100px;">

<?
for ($i=0; $i<$totimg; $i++){
echo "<option value=\"$stationID[$i]\">$stationNM[$i]</option> ";
}
?>

</SELECT>
</FORM>
-------------------------------------------

it's a php/js code as u can see
it should allow me to switch an image and its link using a dropdown menu

the image changes correctly but i'm not able to change the link
does anyone know what's wrong with it and how i could fix it?

thanks a lot for your replies :)

orion_rus

3:41 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



Change this
document.weatherImg.src = '<? echo"$path";?>'+ImgID+'.gif';

to this
weatherImg.src = '<? echo"$path";?>'+ImgID+'.gif';
but the better way is to give a weatherImg img id='weatherimg' and replace
document.weatherImg.src = '<? echo"$path";?>'+ImgID+'.gif';
to
document.getElementById('weatherImg').src = '<? echo"$path";?>'+ImgID+'.gif';
Good luck to you

wonderer

9:06 am on Mar 24, 2005 (gmt 0)

10+ Year Member



hello :)
thnx for your answer
i found out where the problem is

it's not in the script cos when i tried it as standalone it was working fine
(i appreciated your corrections)

it seems there r conflicts with another js
but i don't get why

this is the other code that makes it crash:
---------------------------------------------
<form action='index.php' method='post'>
Enter keywords:
<input size="15" class="inputbox" type="text" name="searchword" style="width:128px;" value="Search..." />
<input type="hidden" name="option" value="search" />
<input type="submit" value="GO" class="button" style="width:55px;" />
</form>
---------------------------------------------

what should i edit to make them work together?

thnx :)