Working with checkbox`s and text fields

Discussion in 'PHP' started by PedroG, Apr 3, 2009.

  1. #1
    Hi people, i need a litle help with php if you don`t mind.....




    So thats what i want:

    got a few checkbox`s on my website. Each of them as corresponded code (not visible for now)

    After choosing what "i" want i press submit and i need that that page, shows all the codes of each Checked CheckBox in a Text Field :rolleyes:

    Someone know how to do it ?
     
    PedroG, Apr 3, 2009 IP
    georgege likes this.
  2. aliks0905

    aliks0905 Member

    Messages:
    97
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    41
    #2
    aliks0905, Apr 4, 2009 IP
  3. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    Maybe

    How can i add a code for each checkbox selected using those codes?
     
    PedroG, Apr 5, 2009 IP
  4. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    BUMP!

    Using that code how can i make it inside a text area with a small scroll bar
    I would like to use an background image too


    Does anyone can help me ?!?
     
    PedroG, Apr 19, 2009 IP
  5. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #5
    Do you mean that you want to display all the values from the checkboxes in a textarea field? Or just display them on a webpage? I'm a little confused. But if you are asking about showing them in a textarea field, you can just post back to the form with the value of the textarea set to show the post-values from each checkbox - something like this: (pseudocode)
    
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="checkbox" value="foo" name="checkbox1" />
    <input type="checkbox" value="bar" name="checkbox2" />
    <input type="checkbox" value="foobar" name="checkbox3" />
    <input type="textarea" value="<?php if (isset($_POST['submit'])) { echo $_POST['checkbox1'].$_POST['checkbox2'].$_POST['checkbox3']; } else {} ?>" name="textbox" />
    <input type="submit" name="submit" value="submit info" />
    
    PHP:
    The same can of course be used if you just want to echo the results from the checkboxes to the page - just put the echo-statement from the value into a <p>-tag or something similar
     
    PoPSiCLe, Apr 19, 2009 IP
    georgege likes this.
  6. PedroG

    PedroG Member

    Messages:
    59
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #6
    Not that :(

    What i want is that after choosing certain checkbox´s the website returns a code to the visitor that will be showed inside a textarea.....


    One more thing.
    This page`s code: http://www.roseindia.net/ajax/jquery/multiple-check-box.shtml

    Only returns the checkbox value ..... How do i make to the script returns the text i want ??
     
    PedroG, Apr 19, 2009 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    I'm not really sure I understand your problem - the code I posted above does exactly the same as the elaborate jQuery code in the link you posted - of course, the page will reload if you don't use Ajax/javascript for this, but the code itself works just fine.

    Depending on the values you want returned, you could either make a PHP variable containing whatever you want to be displayed depending on which checkboxes are selected, or just put the whatever you want the checkbox to return into the value="" for each checkbox.

    I'm assuming you want something like "if checkbox 1 selected return "you selected checkbox 1, which has the following code/text attached to it"" - but not show the actual text in the value-part if the user checks the source-code or something?

    Hm, I think maybe I misunderstood you a bit - here is another piece of code that does something more like what you want, I think:
    
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
    <input type="checkbox" value="foo" name="checkbox1" />
    <input type="checkbox" value="bar" name="checkbox2" />
    <input type="checkbox" value="foobar" name="checkbox3" /><br />
    <textarea cols="35" rows="10" value="<?php if (isset($_POST['submit'])) { 
    if (isset($_POST['checkbox1'])) { $value1 = "This is the value returned from the checkbox #1 if checked"; } echo $value1.$_POST['checkbox2'].$_POST['checkbox3']; } else {} ?>" name="textbox"><?php if (isset($_POST['submit'])) { 
    if (isset($_POST['checkbox1'])) { $value1 = "This is the value returned from the checkbox #1 if checked"; } echo $value1.$_POST['checkbox2'].$_POST['checkbox3']; } else {} ?></textarea>
    <br /><input type="submit" name="submit" value="submit info" />
    
    PHP:
    You can find a working test of the example here: http://www.regncon.no/testing/checktest.php
     
    PoPSiCLe, Apr 20, 2009 IP