tags:

views:

21

answers:

1

I've got an SQL database im doing some queries on and filling in a dropdown box with the code.

It's a select/combo box. It returns my database fields.

red black green.

In the source code i modified the query to get a second field in the same table. red.jpg black.jpg green.jpg.

How can i at runtime display a picture of a red shirt using the onChange() function in javascript? I found this online example useful javascriptkit .com/script/cut173.shtml

$interface is my sql query pic1 is the image being changed the html code looks like this Choosered green black

heres the snippets. any help is greatly appreciated. http://pastebin.com/mgqrEiJu

A: 

This should solve your problem. Loop through all the records and print out <option value="$url">$name</option>

Kshitij Parajuli
This is a great answer, the issue i have though is that im using one of the values that mysql returns as the data the form posts. It only works when i change my query to return the values first. But that stops my script from posting "RED", its posting "../images/red.jpg".
dysmantle
Here is what the query returns and prints to HTML.<OPTION VALUE="../images/red.jpg" name="red">
dysmantle
try switching the 'value' and 'name' and change the function to say `imgtag.src=dropdown.getAttribute('name');`
Kshitij Parajuli
its still not working :-( i could post all the code on pastebin if you want to take a peek. What you've responded with looks correct but for some reason the javascript isnt getting the name element anywhere. I'm even printing up a popup box and its returning null.
dysmantle