Click to See Complete Forum and Search --> : Giving a webform 3 values. Is that possible?


Whipsmack
06-01-2004, 03:05 PM
Is it possible to completely seperate values in a drop down menu web form. Heres my problem right now. I've got a webform where when you select an option an image is displayed. Heres the script for that

<script>
function ShowImage(sel,img){
if(sel.selectedIndex>0){
img.style.visibility=""
img.src=sel.options[sel.selectedIndex].value+".gif"
img.title=sel.options[sel.selectedIndex].text
}
else{
img.style.visibility="hidden"
}
}
</script>

What it does is adds .gif to my value so that the name of my value is the name of the image. But I want to be able to have three values one for the name I receive in my e-mail another for for a URL, and a 3rd for the image. ARGHHHH

redijedi
06-01-2004, 04:18 PM
There are at least two ways to do this. One would be to have a delineated string in the value of the select box options. For example value="http://myurl.com|MyURL|myurl.gif". Then you could use javascript's spliot function to retrieve the different values. Probably not how I would do it, but that's one way.

The other way would be to contain all the values you are dealing with in a multidimensional array within the javascript in the page. A choice in the selec box would correspond to an entry in your array from which you can pull the data to do what you want with.

Sloppy example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<script>
var array = new Array(3);
array[0] = new Array(3);
array[1] = new Array(3);
array[2] = new Array(3);

array[0][0] = "mylink.com";
array[0][1] = "myValue";
array[0][2] = "mygif.gif";
array[1][0] = "mylink1.com";
array[1][1] = "myValue1";
array[1][2] = "mygif1.gif";
array[2][0] = "mylink2.com";
array[2][1] = "myValue2";
array[2][2] = "mygif2.gif";

for (i=0; i<array.length; i++)
for (j=0; j<array[i].length; j++)
document.write(array[i][j] + "<br>");

function test(element)
{
mylink = array[element.options[element.selectedIndex].value][0];
mytitle = array[element.options[element.selectedIndex].value][1];
mysrc = array[element.options[element.selectedIndex].value][2];

test = mytitle + "\n" + mysrc + "\n" + mylink + "\n"

alert(test);

return;
}

</script>

<select id="test" onchange="test(this)">
<script>
for (i=0;i<array.length;i++) {
document.write('<option value="' + i + '">' + array[i][1] + '</option>');
}
</script>
</select>
</body>
</html>


I wrote that in a hurry. You'd want to make it more streamlined of course.

Have fun!