Results 1 to 2 of 2

Thread: Make a Radio Button Selected by PHP Session

  1. #1
    Join Date
    Feb 2008
    Posts
    83
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Make a Radio Button Selected by PHP Session

    On the product pages we have a code like this:
    Code:
    <select name="paymentmethod1" id="paymentmethod1">
    <option value="MoneyPak">MoneyPak</option>
    </select>
    
    
    <select name="paymentmethod2" id="paymentmethod2">
    <option value="MoneyPak">MoneyPak</option>
    </select
    etc.

    Through Session it writes to the order checkout form header as text such as MoneyPak or Credit Card through the code:

    Code:
    <?php echo($_SESSION["paymentmethod".$counter]); ?>
    Now what I am trying to do here is get the user selection of Credit Card or MoneyPak radio button from the product page to automatically trigger the corresponding radio button to be checked:

    Code:
     <input name="1" type="radio" class="radio2" id="creditcard" style="padding-left:0px" 
    onclick="showhide('creditcardxx', 'block'); showhide('m-p-kx', 'none'); 
    showhide('splitx', 'none'); showhide('charge', 'block'); showhide('option3m', 'none'); 
    showhide('option3', 'none'); showhide('option2', 'block')" value="creditcard"/>
    I was thinking it could be something like this maybe but I can't get it to work:

    Code:
    <input name="1" <?php if (echo($_SESSION["paymentmethod".$counter])=='MoneyPak') {
    echo checked="checked" ;} ?> type="radio" class="radio" id="MoneyPak" 
    onclick="showhide('m-p-kx', 'block'); showhide('splitx', 'none'); 
    showhide('creditcardxx', 'none'); showhide('paypalx', 'none'); showhide('charge', 
    'none'); showhide('option3', 'none'); showhide('option3m', 'none'); showhide('option2', 
    'none');" value="MoneyPak">
    I also don't know if I should have else in both radio buttons or not.

  2. #2
    Join Date
    Feb 2014
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Maybe
    <input type="radio" name="whatever" value="whatever" <?php if(isset(session) && session == whatever_value){echo checked="checked";} ?> />
    or something like that

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2013, 10:52 PM
  2. Replies: 14
    Last Post: 08-27-2012, 09:49 AM
  3. Replies: 1
    Last Post: 05-06-2009, 01:41 AM
  4. Replies: 2
    Last Post: 07-06-2008, 02:21 PM
  5. plugging in selected radio button values
    By heimskr in forum JavaScript
    Replies: 0
    Last Post: 11-10-2006, 04:20 PM

Tags for this Thread

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
  •