PHP radio button condition

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xamonix
Forum Newbie
Posts: 6
Joined: Fri Sep 24, 2010 8:42 am

PHP radio button condition

Post by xamonix »

Hi
I'm trying to modify a Shipping module for an online shop but I'm not getting it to work...I want to put two options on that, if customer chooses first option he gets one price for the shipment if he chooses second option then he gets a different price.

The original module only allows one option for Shipment Method and I want to add a second option using two radio buttons.

Basically I want to check what radio button is selected and then get the value, if first radio button is checked get it's value if the second radio button is checked get the previous value plus and aditional tax.
Here goes the code:

Code: Select all

 $_SESSION[$value] = "1";
      $string = "&nbsp;<input type=\"radio\"  id=\"radio1\" name=\"shipping_rate_id\" value=\"$value\" />";
      $string .= "  Zone Shipping -  $country_name <strong><div class='zone'>". $CURRENCY_DISPLAY->getFullValue($rate )."</div></strong>";
      $string .= "<br />&nbsp;<input type=\"radio\"  id=\"radio2\"name=\"shipping_rate_id\" value=\"$value\" />";
      $string .= "  Contra Re-embolso (+ 1.50€)<strong><div class='zone'>". $CURRENCY_DISPLAY->getFullValue($rate+1.50 )."</div></strong>";
      echo $string;
    }
	
  function get_rate( &$d ) {	
      
	  if (document.getElementById("radio2").checked) {
      $shipping_rate_id = vmGet($_REQUEST,"shipping_rate_id")+1.50;
	  $zone_arr = explode("|", urldecode(urldecode($shipping_rate_id)) );
	  $order_shipping = $zone_arr[3];
      } else {
	  $shipping_rate_id = vmGet($_REQUEST,"shipping_rate_id");
	  $zone_arr = explode("|", urldecode(urldecode($shipping_rate_id)) );
	  $order_shipping = $zone_arr[3];
	   }
	  
	  return $order_shipping;
  }
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: PHP radio button condition

Post by Jonah Bron »

xamonix wrote:if (document.getElementById("radio2").checked) {
You can't do that, that's Javascript. I don't understand how your code works, could you explain it? What error do you get?
Post Reply