Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    checkbox value = an image

    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.

  • #2
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    What do you want to do with the image?

    You could have something like this.

    Code:
    <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.

  • #3
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <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

  • #4
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    Quote Originally Posted by JohnnyCK View Post
    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.

    Quote Originally Posted by JohnnyCK View Post
    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.

  • #5
    New to the CF scene
    Join Date
    May 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •