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 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2005
    Posts
    77
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Toggling Display with Checkbox

    All,

    Totally frustrated! Have checkbox and need to toggle display with it. Basically have the following code:
    Code:
    <html>
    <? echo $def_dis = default_display (); ?>   // get the default display html
    <input name=mycheck type=checkbox> Advanced Search
    <br>
    <?
       if (mycheck=='on') { echo $adv_dis = advanced_display(); } //get the advanced display html
    ?>
    </html>
    Problem is when it turns on it will not turn off and when the "Search" button on the page is clicked currently throws errors, so really frustrated.

    Additional frustration, is I can find only 2 examples of this and when entering "php toggle display with checkbox" I only get $##@$%%^ JavaScript, instead of PHP. I totally hate search engines that "GUESS" what I'm searching for. When I say "PHP" I want to see only PHP solutions, not friggin jAVAsCRIPT!

    Because of this SE bullcrap, having to take time to write this up and hate wasting precious coding time.

    All help with this appreciated!

    OMR

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    With PHP, you'll need to do a refresh ... otherwise, javascripting (ajax) needs to be used. It seems like you want an instant action using javascripting?

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    Mmm yep. Unfortunately this is a limitation of HTTP protocol being stateless.
    From what I read into it as well, you are looking for a click > toggle. That is an event, so you'll need a language that will handle that (javascript in the case of text and html). HTTP is stateless so there is no way to gather an onclick event in PHP; the only thing PHP can do is wait for a new request via a form submission.
    So I'm afraid the answer really is by using javascript.

    PHP wise, if you submit the form (so you will need a submit button for it), you can then change the behaviour based on the input received from the checkbox. Simply check for the isset state.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,472
    Thanks
    8
    Thanked 1,085 Times in 1,076 Posts
    And if a refresh is OK then you can also use a session or cookie to remember the state of the checkbox.


  •  

    Posting Permissions

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