+ Reply to Thread
Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: Image checkbox

  1. #1
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Question Image checkbox

    Is it possible to substitute a checkbox for an image so that I can post user selections to myself? If so can anyone suggest how..?

    I've used
    Code:
    input type='image' value='Submit'
    to make an image a submit button so I am hoping I can do something similar with the checkbox.

    Indebted

  2. #2
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Image checkbox

    I don't really understand but if you are trying to substitute the normal, semi-ugly checkboxes for your own images, it's possible with a bit of javascript.

    Quickly written code below (untested):

    HTML Code:
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "chkbox_empty.png";
    function submitcheckboxes(){
    var checkboxes = document.getElementsByName("imgcheckboxes");
    for(var i in checkboxes){
    var location = document.getElementById("form1");
    var input = document.createElement('input');
    input.setAttribute('style','display:none;');
    input.setAttribute('type','hidden');
    input.setAttribute('name',checkboxes[i].title);
    if(checkboxes[i].src = "chkbox_ticked.png"){
    input.setAttribute('value',1);
    } else {
    input.setAttribute('value',0);
    }
    location.appendChild(input);
    }
    return true;
    }
    function toggleChkBox(that){
    if(that.src == chkboxEmpty.src){
    that.src = chkboxTicked.src;
    } else {
    that.src = chkboxEmpty.src;
    }
    }
    </script>
    <form id="form1" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox1" />
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox2" />
    </form>
    Just need to make two images called chkbox_empty.png and chkbox_ticked.png
    Last edited by scopey; 09-27-2008 at 10:57 PM.
    - When in doubt, refer to the PHP manual.

  3. #3
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: Image checkbox

    seems good and from there ... how do I get this information posted to me on the next page as I seem to be having a little trouble with the php coding that I have used on previous forms. It is below.

    PHP Code:
    <script language="php">
    $email $HTTP_POST_VARS[email];
    $mailto "my.email@myhost.com";
    $mailsubj "Title";
    $mailhead "From: $email\n";
    reset ($HTTP_POST_VARS);
    $mailbody "Data received:\n";
    while (list (
    $key$val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
    if (!
    eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto$mailsubj$mailbody$mailhead); }
    </script> 

  4. #4
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Image checkbox

    $HTTP_POST_VARS is now deprecated... Use $_POST[] instead.

    To get whether the person ticked your checkbox or not, you just need to get $_POST['(Title of your checkbox img tag here)'] . The value should be 1 if it was ticked, and 0 if it was left empty. The code is probably buggy though... I will give it a test.

    [Edit]

    Wow, suprised I almost got my script perfect. The only mistakes I made was a couple of typos:

    HTML Code:
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "chkbox_empty.png";
    function submitcheckboxes(){
    var checkboxes = document.getElementsByName("imagecheckboxes");
    for(var i in checkboxes){
    var location = document.getElementById("form1");
    var input = document.createElement('input');
    input.setAttribute('style','display:none;');
    input.setAttribute('type','hidden');
    input.setAttribute('name',checkboxes[i].title);
    if(checkboxes[i].src == chkboxTicked.src){
    input.setAttribute('value',1);
    } else {
    input.setAttribute('value',0);
    }
    location.appendChild(input);
    }
    return true;
    }
    function toggleChkBox(that){
    if(that.src == chkboxEmpty.src){
    that.src = chkboxTicked.src;
    } else {
    that.src = chkboxEmpty.src;
    }
    }
    </script>
    <form id="form1" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox1" />
    <img name="imagecheckboxes" src="http://forums.x10hosting.com/programming-help/chkbox_empty.png" onclick="toggleChkBox(this)" title="checkbox2" />
    </form>
    Last edited by scopey; 09-29-2008 at 02:24 AM.
    - When in doubt, refer to the PHP manual.

  5. #5
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: Image checkbox

    scopey this code looks good but I'm having a few problems with my php - I changed all the $HTTP_POST_VARS to $_POST[] but it doesn't want to work for me and I didn't know quite in what place to enter the $_POST[checkbox1].

    ...code looks awesome though/.

  6. #6
    scopey is offline x10Hosting Member scopey is an unknown quantity at this point
    Join Date
    May 2008
    Posts
    62

    Re: Image checkbox

    Ok... This is the PHP page I was testing it with:

    HTML Code:
    <?php
    print_r($_POST);
    ?>
    
    <script type="text/javascript">
    var chkboxTicked = new Image();
    chkboxTicked.src = "test/chkbox_ticked.png";
    var chkboxEmpty = new Image();
    chkboxEmpty.src = "test/chkbox_empty.png";
    function submitcheckboxes(){
        var checkboxes = document.getElementsByName("imagecheckboxes");
        for(var i in checkboxes){
            var location = document.getElementById("form1");
            var input = document.createElement('input');
            input.setAttribute('style','display:none;');
            input.setAttribute('type','hidden');
            input.setAttribute('name',checkboxes[i].title);
            input.setAttribute('id',checkboxes[i].title);
            location.appendChild(input);
            if(checkboxes[i].src == chkboxTicked.src){
                document.getElementById(checkboxes[i].title).value = "1";
            } else {
                document.getElementById(checkboxes[i].title).value = "0";
            }
        }
        return true;
    }
    function toggleChkBox(that){
        if(that.src == chkboxEmpty.src){
            that.src = chkboxTicked.src;
        } else {
            that.src = chkboxEmpty.src;
        }
    }
    </script>
    <form id="form1" method="post" action="tester.php" onsubmit="return submitcheckboxes()">
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box1" />
    <img name="imagecheckboxes" src="test/chkbox_empty.png" onclick="toggleChkBox(this)" title="box2" />
    <input type="submit" name="submit" />
    </form>
    For me, that returned:

    Code:
    Array (     [submit] => Submit Query     [box1] => 0     [box2] => 1     [undefined] =>  )
    See the names of my image tickboxes are box1 and box2? That's how the tickboxes are submitted.

    So, if you put in php:

    PHP Code:
    <?
    if($_POST['box1'] == 1){
    print 
    "Box 1 was ticked";
    }
    ?>
    It will write 'Box 1 was ticked' if box 1 was ticked.

    Similarly, you can just write the following for the same result:

    PHP Code:
    <?
    if($_POST['box1']){
    print 
    "Box 1 was ticked";
    }
    ?>
    - When in doubt, refer to the PHP manual.

  7. #7
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: Image checkbox

    That's very useful scopey. . .thanks a lot. I just need to mail it to myself now and if possible remove the ones that haven't been checked. Also wanted to ask you if it was possible to make the images on the results page the same as they were as they were submitted on the previous but I don't want to ask too much of you so anything more you can add or not is great - you've really helped me already. .
    -------------------------------------------------------------------------------------------------------------------------
    Here is the php (below) that I have it working for but wanted to ask if it is possible to have only the images selected mailed to me. . . . without being too picky.

    PHP Code:
    <?php 

    // Create local PHP variables from the info the user gave in the Flash form -disabled message field 
    $box1   $_POST['box1']; 
    $box2   $_POST['box2']; 

    // Strip slashes on the Local variables -disabled message field 
    $box1  stripslashes($box1); 
    $box2      stripslashes($box2); 

        
    $from $fromEmail
        
    $subject "Spaces chosen"
        
    //Begin HTML Email Message 
        
    $message "<b>Box 1:</b><br>{$box1} <br><br> <b>Box 2:</b><br>$box2";
        
        echo 
    '
    '
    ;
       
    //end of message 
        
    $headers  "From: $from\r\n"
        
    $headers .= "Content-type: text/html\r\n"
        
    $to "reg.brooks@hotmail.com"

        
    mail($to$subject$message$headers); 
         
    exit(); 
    ?>
    Last edited by bunglebrown; 09-30-2008 at 04:56 PM.

  8. #8
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Image checkbox

    Sure that should be easy. I've not gone through your whole discussion but from what I remember correctly, the logic in my opinion would be this.

    After
    Code:
    $box1  = stripslashes($box1);
    $box2      = stripslashes($box2);
    Add
    Code:
    if ($box1 == "1") { // If the box is ticked
    $box1 = "<img src='test/chkbox_ticked.png'>";
    }
    else {
    $box1 = "<img src='test/chkbox_empty.png'>";
    }
    
    if ($box2 == "1") { // If the box is ticked
    $box2 = "<img src='test/chkbox_ticked.png'>";
    }
    else {
    $box2 = "<img src='test/chkbox_empty.png'>";
    }
    You should include the whole path of the image (starting with http://) for your browser to find it when you read it in your e-mail though. If I'm not mistaken, this should echo your boxes images instead of the number that represents their value.

  9. #9
    bunglebrown is offline x10 Sophmore bunglebrown is an unknown quantity at this point
    Join Date
    Aug 2008
    Posts
    157

    Re: Image checkbox

    thanks Salvatos...

    this is a nice idea but doesn't seem to send the images as they were submitted..

    Also what I meant to say is that I want the images to be as they were on the next page and only the title of the selected images mailed to me (the mailing has been achieved). .

    Would be unreal if this worked though..

  10. #10
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: Image checkbox

    When you say "next page", do you mean that you want to replace this
    Code:
    if($_POST['box1'] == 1){
    print "Box 1 was ticked";
    }
    By the image?

+ Reply to Thread
Page 1 of 3 123 LastLast

Similar Threads

  1. [java]background image
    By galaxyAbstractor in forum Programming Help
    Replies: 8
    Last Post: 09-13-2008, 02:12 PM
  2. 3000 credits for header image
    By bigjoe4 in forum The Marketplace
    Replies: 44
    Last Post: 05-02-2008, 11:35 AM
  3. Looking for a free pdf to image converter
    By Christopher in forum Off Topic
    Replies: 8
    Last Post: 01-11-2007, 03:50 PM
  4. errors while attaching
    By mattspec in forum Feedback and Suggestions
    Replies: 0
    Last Post: 12-19-2005, 01:50 PM
  5. November Desktop
    By n4tec in forum Off Topic
    Replies: 12
    Last Post: 11-08-2005, 07:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers