Click to See Complete Forum and Search --> : ID Value from a looped series of images


bodywise
01-12-2003, 09:14 PM
I am trying to find the write javascript for the following:

I have a form that loops through about 4-8 product images each of which has a product ID.

I simply need to know how to pass the ProductID variable once a product has been clicked. I am close, but can't quite get this, since this is once again just a little different than most routines.

It's the line onClick="this.ProductSelect.ProductID.value">
that I cannot figure out. I need to know how to set the form.value = ProductID statement

The smart ones here will know this right away:

<form name="ProductSelect" method="POST" action="catalog.php">

<table ...>
<tr>
<?php do { ?>
<td>
<input name="ProductID" type="image" value="0" src="<?php echo $xx['ImgSrc']; ?>"
<input name="ProductID" type="hidden" value="103" onClick="this.ProductSelect.ProductID.value">
</td>
<?php } while ($xx = mysql_fetch_assoc($xx)); ?>
</tr>
</table>
</form>

khalidali63
01-12-2003, 11:11 PM
Well I am not sure if this is exactly what you wanted,Its not the best code but it might work for you.
Khalid


<html>
<head>
<title>Untitled</title>
</head>

<body>
<form name="ProductSelect" method="POST" action="catalog.php">

<table ...>
<tr>
<!--<?php do { ?>-->
<td>
<img name="ProductID" type="Image" value="0" src="<?php echo $xx['ImgSrc']; ?>" onclick="passValue();"><br><br>
<img name="ProductID" type="Image" value="1" src="<?php echo $xx['ImgSrc']; ?>" onclick="passValue();"><br><br>
<img name="ProductID" type="Image" value="2" src="<?php echo $xx['ImgSrc']; ?>" onclick="passValue();"><br><br>
<input name="ProductIDHidden" type="hidden" value="100">
<input name="ProductIDHidden" type="hidden" value="101">
<input name="ProductIDHidden" type="hidden" value="102">
</td>
<!--<?php } while ($xx = mysql_fetch_assoc($xx)); ?>-->
</tr>
</table>
</form>
<script>
function passValue(){
var frm = document.getElementsByTagName("img");
for(x=0;x<frm.length;x++){
document.ProductSelect.ProductIDHidden[x].value = frm[x].value;
alert(frm[x].value)
}
alert(document.ProductSelect.ProductIDHidden[0].value)
alert(document.ProductSelect.ProductIDHidden[1].value)
alert(document.ProductSelect.ProductIDHidden[2].value)
}
</script>

</body>
</html>

bodywise
01-12-2003, 11:50 PM
Khalid,

Thank you. I have always had good luck with this forum, although I always look for the simplest and most elegant solution. Let me play with this overnight and see if it solves the problem. It is a bit more complex than I had suspected.

Again, I am only looking for the ProductID (form POST variable to be passed to the next PHP result page) corresponding to the image that was clicked.

So it is not technically a list, or a menu, or a radio button or check box. It is most like a series of submit buttons all with labels (images in this case).

Many tanks,
Phil