Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old March 10th, 2013, 08:30 PM
Registered User
Points: 10, Level: 1
Points: 10, Level: 1 Points: 10, Level: 1 Points: 10, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Mar 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Red face Using Array photos for buttons

Hello everyone, first post here. I have searched for an answer for my problem and tried many things posted but just can't figure it out. I have created two arrays. One of "photos" and the other of the "name" of the photo. I am using a function randomNum() to generate the selection from the name "name" Array and returning the Name and the index to test against. The problem that I am having is that I want the button to click on populated with each of the 7 images from the photos array. I can not figure how to do this and then display it on the page where I want instead of using document.write(), which opens up a new page.
here is my code that I have written so far;

<script type="text/javascript">

var photos= new Array(7)

photos[1]= "images/leafedge1.jpg"; 
photos[2]= "images/leafedge2.jpg";
photos[3]= "images/leafedge3.jpg";
photos[4]= "images/leafedge4.jpg";
photos[5]= "images/leafedge5.jpg";
photos[6]= "images/leafedge6.jpg";
photos[7]= "images/leafedge7.jpg";

var leafArray= new Array(7);

leafArray[1] = "Entire";
leafArray[2] = "Undulate";
leafArray[3] = "Finely Serrated";
leafArray[4] = "Coursely Serrated";
leafArray[5] = "Doubly Serrated";
leafArray[6] = "Crenate";
leafArray[7] = "Lobed";

function randomNum(){
 firstRandomNumber = (Math.round((Math.random()*6)+1))
  	ans = (leafArray[firstRandomNumber]+"</br>");
	num = (firstRandomNumber);
	return ans;
	return num;

function checkAns(){



 <body bgcolor="#ffffdd">
  <form name ="answers">
<img src="treeImage.jpg" alt="Tree Image" height="850" width="542">
  <input type="submit" value="Refresh"/>

<p>Click the button to trigger a function.</p>

<button src= leafEdge1.jpg onclick="randomNum()">Click for the leaf challenge</button>
<p id="leaf"></p>


i was able to get the buttons as the images using the src tag but not using the Array. The purpose of the button is to ask the question populated by the ''name" array in the question and then display the images so that one may click on it for to check the answer. I am thinking that I need to use the array so that I can check the index of the array against the index of the image and if they match, they have a correct answer. my coding is probably terrible, but i am trying to learn. Any help at all would be much appreciated.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to add 5 more photos js32821 BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 5 September 3rd, 2007 12:48 PM
Displaying photos via a database Mike707 Dreamweaver (all versions) 12 April 17th, 2006 12:33 AM
Ridiculus photos shapira BOOK: Professional Crystal Reports for VS.NET 0 March 7th, 2005 08:11 PM
Uploading Photos microchip Classic ASP Basics 6 April 25th, 2004 10:15 AM
Photos in access kev_79 Access 1 July 24th, 2003 02:24 PM

All times are GMT -4. The time now is 04:31 AM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.