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

Adding an onclick to this (array)?

Status
Not open for further replies.

Wulfgen

Technical User
Dec 31, 2004
283
US
Hello All,

I have been muddling through with this script - however, I'm at an impasse with it - I'm trying to add an onclick to the images displayed, or in the array

Code:
<table width="620" height="121"  border="0" cellpadding="0" cellspacing="0">
                      <tr>
                        <td height="121"><SCRIPT LANGUAGE="JavaScript">
var Image_array = new Array();
//new Array("Image location",width,height,"description image")
Image_array[0] = new Array("eco_img/bags/mens/2559.jpg",600,285,"&nbsp;&nbsp;BG2559 - Tiger");
Image_array[1] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[2] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[3] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[4] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[5] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[6] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
Image_array[7] = new Array("eco_img/bags/mens/2558.jpg",600,285,"&nbsp;&nbsp;BG2558 - Black Rhino");
//If you want to add  more images use Image_array[etc]= ...


function setf(thisv)
{
  img_changer.src = Image_array[thisv][0];
  img_changer.style.width = Image_array[thisv][1];
  img_changer.style.height = Image_array[thisv][2];
}
                          </script>
                          <center>
                            <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                                <tr>
                                  <td></td>
                                  <td width="12%"><select onChange="setf(this.selectedIndex)">
                                      <script language=javascript>
							for(i=0;i<Image_array.length;i++)
{
 document.write("<option>" + Image_array[i][3]);
}
                              </script>
                                  </select></td>
                                  <td width="38%"></td>
                                </tr>
                            </table>
                              <br>
                              <br>
                              <img name=img_changer border=0>
                          </center>
                            <script language=javascript>setf(0);</script>
                        </td>
                      </tr>
                  </table>

what this does is display an image in the array using a drop menu.... what I need to add is the ability to click on the displayed image and go to either a new page (_blank) or (_self)

Is this doable??

regards............
 
Oops - forgot to add this:

<select onChange="setf(this.selectedIndex)">
<script language=javascript>
for(i=0;i<Image_array.length;i++)
{
document.write("<option>" + Image_array[3]);
}
</script>
</select>
 
Try this:

Code:
function setf(thisv) {
   img_changer.src = Image_array[thisv][0];
   img_changer.style.width = Image_array[thisv][1];
   img_changer.style.height = Image_array[thisv][2];
   [!]img_changer.onclick = function() { window.open('', '', ''); };[/!]
}

That should open a new window when any of the images are clicked.

You didn't mention anything about the contents of the new window being populated with anything, so I assumed you didn't want that.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
window.open('', '', '');

I put the code in place and tested it with _self in the second set of parenthesis and it opens a page in itself just fine - however - I have over 14 bag descriptions, so can it use from the option (if its added) the url specific to the image?

thanks for your help
 
window.open('this.src', '_self', '') tries to open a file called this.src

so I used this instead:

<script language="javascript">

function linkrotate(which){
var mylinks=new Array()
//add in more links if you want (ie:mylinks[3]=...)
mylinks[0]="mylinks[1]="mylinks[2]="
window.location=mylinks[which]
}


function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.mygallery.picture.options[document.mygallery.picture.selectedIndex].value
}
//-->
</script>
<form name="mygallery">
<select name="picture" size="1" onChange="showimage()">
<option selected value="eco_img/bags/choose.jpg">&nbsp;&nbsp;Choose a Bag...</option>
<option value="eco_img/bags/mens/2558.jpg">&nbsp;&nbsp;BG2558 - Black Rhino</option>
<option value="eco_img/bags/mens/2559.jpg">&nbsp;&nbsp;BG2559 - Tiger</option>
<option value="eco_img/bags/mens/2572.jpg">&nbsp;&nbsp;BG2572 - Loggerhead</option>
</select>
 
I think what BillyRay meant was....

window.open(this.src, '_self', '')
 
Hi BRPS

sounds like (BuRPS) sorry ;-) I used the second script {I had the client over my shoulder - literally - and didnt have the time to get it right, however, I am going to use it later - for the moment I'll use the script but a single array is way better than two - so I'll slip it in later...

thanks for the help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top