1
    echo    "<form class='custom'>";
foreach ($prices->item as $item){
      $ongkir = $item->value;
      $transfer = $total_jne * 1000;
      $transfer_rp = $transfer + $ongkir;
      $jne = $item->service;
      $checked = ($jne == $_POST['ongkir'])? ' checked="checked"' : '';
      echo  "<tr><td><label for='$item'>
      <input class='custom' name='ongkir' $checked type='radio' id='ongkir'> $jne</label></td>";
      echo  "<td>Rp. $ongkir</td>";
      echo  "<td>Rp. $transfer_rp</td></tr>";}
      echo  "</table><hr></form>" ;
    }

Hi Everybody, how do i post "checked" with value='$transfer_rp' to another php file with button? :(

3
  • you could help by explaining what $checked is a place holder for? Commented Mar 31, 2013 at 23:14
  • 2
    You need a <form action="other-php-file.php"> tag, if you have none yet. Commented Mar 31, 2013 at 23:14
  • What do you mean exactly? Are you talking about submitting the form to another php file? - as mario said, you need to specify the file in form action. Would you like to just get the $checked value while it is being changed and use that value to send to another php file? - you need to catch the radio button change event on the client side and use AJAX to communicate with PHP. Commented Mar 31, 2013 at 23:23

1 Answer 1

1

The radio input will come as "true" or "false", not as the value of its name property, so try

$checked = ($jne == 'ongkir' && isset($_POST['ongkir']) && $_POST['ongkir'] == "true" )? ' checked="checked"' : '';

Or alternatively since this is ugly

$checked = '';
if( $jne == 'ongkir' && isset($_POST['ongkir']) && $_POST['ongkir'] == "true" ){
    $checked = 'checked="checked"';
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.