...

View Full Version : checkbox value = an image



JohnnyCK
05-11-2011, 05:27 AM
Im trying to make a very simple form with a checkbox that returns an image as a value instead of some text.

<input type="checkbox" name="pic1" value=Penguins.jpg />

This was my best guess but it did not work.

Taught myself HTML with trial and error so google is usually my best friend but haven't had any luck with this one.

bullant
05-11-2011, 05:41 AM
What do you want to do with the image?

You could have something like this.


<scipt type="text/javascript">

var myPics = ['pic1.jpg','pic2.jpg','pic3.jpg'];

</script>

<input type='checkbox' name='chk1' id='chk1' value='0' />

<input type='checkbox' name='chk2' id='chk2' value='1' />


where the value for each checkbox is the index for the appropriate image in the myPics array.

JohnnyCK
05-11-2011, 07:30 AM
<script type="text/javascript">
var myPics = ['Dock.jpg', 'Creek.jpg'];
</script>
</head>
<body>

<form action="process.php" method="post">
<input type="checkbox" name="dock" id='chk1' value='[0]' />
<img src="Dock.jpg" width="1024" height="768" alt="dock" />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>

This only returns exactly what I have entered in the value="". It does not pull the image from the array.

Doubt you need this but this is the code for the process page:
<body>
<?php
$dock = $_POST['dock'];
echo "$dock";
?>
</body>

So my problem is that when I hit the Submit button, the process page displays [0] and not the first image in the array myPics

bullant
05-11-2011, 07:59 AM
This only returns exactly what I have entered in the value="". It does not pull the image from the array.


Which is exactly what you are telling your code to do. Also, you haven't set the value attribute as I did in the demo.



So my problem is that when I hit the Submit button, the process page displays [0] and not the first image in the array myPics

That's because you haven't passed the correct value. The actual array index values do not include [] around them. Index values are just integers.

I assume you are aware that javascript is executed in the browser and php is executed on the web server before any outputed html is sent back to the browser, so where is the pics array in your php script?

You still haven't answered my original question -


What do you want to do with the image?

and now you are including php code which you didn't mention in your op.
It appears to me you are either making this up as you go along or you are dripping feeding information so I can't help anymore.

JohnnyCK
05-11-2011, 08:56 AM
I added the php after my original response. 100% of my php experience is in the example I linked, I literally just started teaching myself after my original post. So yes, I kind of made that up as I went along.

Im trying to build a "Add Pictures" page that contains a bunch of images with checkboxes next to them. User checks the boxes of the pics they want, hit submit, and pictures move to the "View Pictures" page where they will be viewed in a slideshow-like object.

Trying to tackle this one step at a time with the Add Pictures page first.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum