Javascript question: using the image button


 
Thread Tools Search this Thread
Top Forums Programming Javascript question: using the image button
# 1  
Old 02-16-2013
Javascript question: using the image button

I have javascript that I want to use to build up a dynamic array: the user clicks on one or more images and when clicking the Show button, the list of image names is displayed that the user clicked.

Code:
<script type="text/javascript">

var images = [];
images[1] = "https://www.unix.com/images/image01.jpg";
images[2] = "https://www.unix.com/images/image02.jpg";
images[3] = "https://www.unix.com/images/image03.jpg";
images[4] = "https://www.unix.com/images/image04.jpg";

for (var i in images)
   document.write('<input name="myImage' + i + '" id="myImage' + i + '" type="image" src=' + images[i] + ' alt="Add me..." onclick="add();" />');

var arr = [];

function add() {
   var inp = document.getElementById('myImage1');
   arr.push('myImage1');
   inp.value = '';
}

function show() {
   document.getElementById('container').innerHTML = arr;
}

</script>

<input type="button" onclick="show();" value="show" />
<div id="container"></div>

The code has a function add() which is obviously wrong, but has at least a sample value to show what happens when an image is clicked and subsequently the Show button.

How do I correct the code to only show the names of the images that the user clicked?


SOLVED:

Code:
<script type="text/javascript">

var images = [];
images[1] = "images/image01.jpg";
images[2] = "images/image02.jpg";
images[3] = "images/image03.jpg";
images[4] = "images/image04.jpg";

for (var i in images)
   document.write('<input name="myImage' + i + '" id="myImage' + i + '" type="image" src=' + images[i] + ' alt="Add me..." onclick="arr.push(\'myImage' + i + '\')" />');

var arr = [];

function show() {
   document.getElementById('container').innerHTML = arr;
}

</script>

<input type="button" onclick="show();" value="show" />
<div id="container"></div>


Last edited by figaro; 02-17-2013 at 07:34 AM.. Reason: Solved
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

This must be the dumbest question ever posted -T5140 power button

I have a T5140 and cannot find the power switch -is there an on/off button? Good grief ! Thank you in advance. joe (3 Replies)
Discussion started by: joboy
3 Replies

2. Shell Programming and Scripting

matching image files to create one image

Hi, I have two sets of image files. Both sets have names A to Z but set 1 ends with .cdt.png and set 2 ends with .matrix.png. I want set 1 to match with set 2 if the names match (i.e. A.cdt.png will match with A.matrix.png) and with the convert image tool (program for images), it will merge the... (6 Replies)
Discussion started by: kylle345
6 Replies

3. Programming

Looking For the Best Way to Rotate an Image: JavaScript, PHP, HTML etc

Hey All, What I'm looking for is a way to rotate an image by non 90 degree angles (ie 90, 180, 270, 360). I am able to do it in PHP, but there are errors in the image, some pixels end up colored incorrectly and the image ends up resized and I lose transparency. I've done my share of searching on... (1 Reply)
Discussion started by: pmd006
1 Replies

4. Solaris

Jumpstart Question: Update Image?

Hi everyone, We have a T5240 and noticed we were having issues booting the system using our jumpstart server (it seems as though we don't have the correct drivers for the nxge NIC) We thought we needed to update our jumpstart server image 9/10 Solaris SPARC image. Now I'm still learning... (4 Replies)
Discussion started by: Keepcase
4 Replies

5. Shell Programming and Scripting

Simple question: Tcl button color

Hey, Can anyone tell me what is the default tcl button color is? I've already tried gray60/70/80/85/90/95. None are the same. Thanks, Phil. -----Post Update----- You can disregard this question, found the color in #E0DFE3 (0 Replies)
Discussion started by: Phi01
0 Replies

6. UNIX for Dummies Questions & Answers

onChange + javascript in perl CGI - question

Hello all, Am trying to include a onChange java script to my perl CGI application which uses POST method to upload files to file_server This is how I embedded javascript in the perl code that renders CGI application print qq| <script type="text/javascript" src="display.js"> </script>... (4 Replies)
Discussion started by: matrixmadhan
4 Replies

7. UNIX for Dummies Questions & Answers

Changing middle mouse button for pasting to right mouse button in cygwin rxvt

Hi, I'm using rxvt in Cygwin and I'm wondering how to change my mouse bindings from the middle button for pasting to the right button. The main reason why I want to do this is because my laptop doesn't have a middle mouse button. Thanks for any help! (2 Replies)
Discussion started by: sayeo
2 Replies

8. Shell Programming and Scripting

need help with html button

Hello everyone, I am trying to implement an html button that will call a script and pass two arguments "perl script.pl website.com 1" this is for a search results page on a php spider called "sphider". the variable $url? is the url and Than needs to be one of the arguments in calling the script.... (0 Replies)
Discussion started by: mike171562
0 Replies

9. UNIX for Advanced & Expert Users

Create an Ignite image on tape from Online IgniteUX image

Hi, (HP-UX 11.11) I need to create a tape image of an igniteUX image created on our igniteUX server. That is to say. I have a "Online" image of the igniteUX of the targeted system but I now need to copy it to a useable TAPE (igniteUX) image so i can build an other server from it that is not... (3 Replies)
Discussion started by: Andrek
3 Replies

10. UNIX for Dummies Questions & Answers

Script for using the Back button and the Close button

Here's a question I have for anyone that might be able to help me: I can write a html script that will allow the user to return to the previous page using the back button, and I can write a script that will allow the user to return to the previous page using the close button, but...is there a... (1 Reply)
Discussion started by: mdgibson
1 Replies
Login or Register to Ask a Question