keeping radio buttons checked after form submit

后端 未结 2 1926
一个人的身影
一个人的身影 2020-12-20 00:44

I have two set of radio buttons in html form button and button1. I am using below code to

1.keep the default value checked (

2条回答
  •  半阙折子戏
    2020-12-20 01:25

    I had a similar problem recently, but had a lot more radio buttons to deal with, so I thought I'd abstract away the value checking functionality into a method that also creates the radio button itself, therefore minimising repetitive value-checking code. I've reworked mine to suit your variable names:

    function createRadioOption($name, $value, $onClickMethodName, $labelText) {
    
      $checked = '';
      if ((isset($_POST[$name]) && $_POST[$name] == $value)) {
        $checked = ' checked="checked"';
      }
    
      echo('');
    }
    
    

提交回复
热议问题