...

View Full Version : Can't display an Image based on a VAR



StepTech
08-26-2007, 09:42 PM
I'm trying to debug a script that I added to which asks a multiple-choice question based on the image displayed. The question and choices come up and eveything works fine except the image is not displayed. Any help?

Inside the <javascript> tags are three pertinent lines:

var picture = new Image();

picture[1] = "lynda005.jpg"
picture[2] = “jenny009.jpg” etc…

document.mc.cp.value=picture[NextQ ]

And in a Form:

<img name="cp" width="350" height="450" value="">

StepTech
08-26-2007, 09:55 PM
I just figured it out...it should be:

document.mc.cp.src=picture[NextQ ]
and not
document.mc.cp.value=picture[NextQ ]

rwedge
08-26-2007, 10:40 PM
var picture = new Image();
picture[1] = "lynda005.jpg"
Arrays start at [0]


And in a Form:
<img name="cp" width="350" height="450" value="">
That is not valid form input code

Here's and example
<script type="text/javascript">
window.onload = function() {
var picture = [
['lynda005.jpg'],
['jenny009.jpg'],
['jenny010.jpg'] // no comma needed after last member
];
document.getElementById('cp').src = picture[0]; // change 'cp' image src to first member
document.getElementById('txt').value = picture[1]; // send 2nd member to text field
}
</script>

<img id="cp" width="350" height="450" alt="" src="lynda004.jpg" />

<input type="text" id="txt" value="" />



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum