SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Changing a Radio Button to a Check Box - help please

    I have this Radio button code,

    PHP Code:
    <td width="16%" align="right">Bus Stop  : &nbsp;</td>
          <td width="16%" align="center">
          <input type="radio" name="vh_3R9" value="1"
          <? echo ($item_details['vh_3R9']=='1') ? "checked":""?>>
          <span style="COLOR: rgb(96,191,0); FONT-WEIGHT: bold">Yes</span>
          <input type="radio" name="vh_3R9" value="0"
          <? echo ($item_details['vh_3R9']=='0') ? "checked":""?>>
          <span style="COLOR: rgb(255,0,0); FONT-WEIGHT: bold">No</span>
        </td>
    that I wanting to change to a Check Box,

    PHP Code:
    <td width="16%" align="right">Bus Stop : &nbsp;</td>
        <td width="16%" align="left">
        <input type="checkbox" name="vh_3R9" value="1" 
        <? echo ($item_details['vh_3R9']==1) ? 'checked' ''?>/>
        </td>
    yet it is not working correctly,

    all help appreciated

  2. #2
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    The problem is likely the processing end of the script. Instead of storing the value of $_POST['vh_3R9'] you'll need to store the value of isset($_POST['vh_3R9']). Technically you should use: $result = isset($_POST['vh_3R9']) ? $_POST['vh_3R9'] : 0; Although you will get away with the former.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello TomB, thank you for your quick helpful reply

    so will each Check Box have a individual $_POST['vh_3R9'] needing to be changed to ($_POST['vh_3R9'])

    or will there be one code to process all ? vh_3R9 vh_3R8 vh_3R7 vh_3R6 ?

    I have not seen any code like this,

    originally there was a drop menu, then I changed it to Radio Buttons.

    PHP Code:
    <td width="16%" align="right">Radio/CD : &nbsp;</td>
        <td width="16%" align="center">
        <select name="vh_20" class="contentfont" id="vh_20" style="height: 20px; width: 170px">
        <option value="" selected>Select Option</option>
        <option value="1" <? echo ($item_details['vh_20']=='1') ? "selected":""?>>Yes</option>
        <option value="0" <? echo ($item_details['vh_20']=='0') ? "selected":""?>>No</option>
        </select>
        </td>

  4. #4
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The only code I can find that has $_POST, and is connected with this is

    PHP Code:
    houseland='" . $_POST['houseland'][$key] . "' WHERE category_id=" . $value); 
    PHP Code:
    $sql_reset_hidden $db->query("UPDATE " DB_PREFIX "categories SET houseland=0 WHERE parent_id=" $parent_id);
            
    $hidden_array $db->implode_array($_POST['houseland']);
            
    $sql_update_hidden $db->query("UPDATE " DB_PREFIX "categories SET
                houseland=1 WHERE category_id IN (" 
    $hidden_array ")"); 

  5. #5
    SitePoint Guru bronze trophy TomB's Avatar
    Join Date
    Oct 2005
    Location
    Milton Keynes, UK
    Posts
    996
    Mentioned
    9 Post(s)
    Tagged
    2 Thread(s)
    You'll need to do the same for any radios you're converting to checkboxes. Somewhere where it process the form it will have to check the value submitted. That's what you need to change.

  6. #6
    SitePoint Addict
    Join Date
    Feb 2012
    Location
    Kiwi in Bangkok
    Posts
    373
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello, are these changes correct?

    was

    houseland='" . $_POST['houseland'][$key] . "',

    now

    houseland='" . isset($_POST['houseland'][$key]) . "',

    .........................................................................

    was

    implode_array($_POST['houseland']);

    now

    implode_array(isset($_POST['houseland']));


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
  •