Results 1 to 2 of 2

Thread: onclick checkbox form submission

  1. #1
    Join Date
    Oct 2007
    Posts
    43
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default onclick checkbox form submission

    I have a little checkbox where people can opt out of receiving a paper version of our newsletter. Using a submit button seems like overkill for one tiny little checkbox. Is there a javascript value that would POST onclick?

    Code:
     <?php 
    if ($tenant->isLoggedIn()) 
    { 
        $tenantDetails = $tenant->getTenantDetails();
    ?><?php } ?>
    
      <form id="news_out" name="news_out" method="post" action="news_ty.php">
    
      <p>
        <input type="hidden" name="name" id="name" value="<?php echo $tenantDetails['tenantName'] ?>" />
        <input name="email" type="hidden" value="<?php echo $_SESSION['tenantEmail'] ?>" />
      </p>
    
      <p>Don't send me a paper copy, I want my Newsletter e-mailed to me. 
         <input <?php if (!$tenant->isLoggedIn()) {echo 'disabled';} ?> type="checkbox" name="newsletter" id="newsletter" />
      </p>
        </form>

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You could try the following (not tested):

    Code:
     <?php 
    if ($tenant->isLoggedIn()) 
    { 
        $tenantDetails = $tenant->getTenantDetails();
    ?><?php } ?>
    
      <form id="news_out" name="news_out" method="post" action="news_ty.php">
    
      <p>
        <input type="hidden" name="name" id="name" value="<?php echo $tenantDetails['tenantName'] ?>" />
        <input name="email" type="hidden" value="<?php echo $_SESSION['tenantEmail'] ?>" />
      </p>
    
      <p>Don't send me a paper copy, I want my Newsletter e-mailed to me. 
         <input <?php if (!$tenant->isLoggedIn()) {echo 'disabled';} ?> type="checkbox" name="newsletter" id="newsletter" onclick="this.form.submit();" />
      </p>
        </form>
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. The Following User Says Thank You to thetestingsite For This Useful Post:

    marynorn (04-08-2008)

Bookmarks

Posting Permissions

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