Get radio value and pass to an input hidden with same name

0

I need to get the value of all the input radio (which are checked) from my page, it is around 10 radius, the value is loaded directly from the database, but they are disabled because the user can not change the value, they are already checked, I need to pass the value of these disabled checkboxes to the input hidden, because as they should know, disabled inputs do not have data sent to php.

Follow the code: link

<div class="form-group">
  <input type="hidden" name="a">
  <div class="radio">
    <label for="yes1">
      <input type="radio" name="a" id="yes1" checked> Yes
    </label>
    <label for="no1">
      <input type="radio" name="a" id="no1"> No
    </label>
  </div>
</div>
<div class="form-group">
  <input type="hidden" name="b">
  <div class="radio">
    <label for="yes2">
      <input type="radio" name="b" id="yes2"> Yes
    </label>
    <label for="no2">
      <input type="radio" name="b" id="no2" checked> No
    </label>
  </div>
</div>
<div class="form-group">
  <input type="hidden" name="c">
  <div class="radio">
    <label for="yes3">
      <input type="radio" name="c" id="yes3" checked> Yes
    </label>
    <label for="no3">
      <input type="radio" name="c" id="no3"> No
    </label>
  </div>
</div>
<button class="btn btn-default">Submit</button>
    
asked by anonymous 17.03.2016 / 13:11

2 answers

1

You can make each one in your radio input by traversing and transferring the values to the input hidden.

I used parent () and sibligns to find the hidden and enter the value.

Example:

$('input[type=radio]').attr('disabled', true);
$('input[type=radio]:checked').each(function() {
   $(this).parent().parent().siblings('input[type=hidden]').val(this.value);
});

See working at jsfiddle

Or as suggested by Philip, add a css simulating the disabled and give a return false.

Example:

$('input[type=radio]').css('opacity', '0.5');
$('input[type=radio]').on('click , keydown', function() {
  return false;
});

See working at jsfiddle

    
17.03.2016 / 13:32
3

Instead of using the disabled property, make the event onclick return false , so the normal action will not be performed and the user will not be able to uncheck the option.

With this solution, your field will be sent in the body of the request message.

<input type="radio" checked onclick="return false;" onkeydown="return false;"/>

There may be a problem, as the option is not disabled and only prevents the user from clicking, you can add the disabled property only in the options that are unchecked:

<input type="radio" checked onclick="return false;" onkeydown="return false;"/> Sim
<input type="radio" disabled onclick="return false;" onkeydown="return false;"/> Não

See working: link

Another option is to use CSS and stylize the input.

You can see in this topic because the above solution works: Why" return false; " , in a click event, cancels the link opening? , although the question depicts a link, the explanation also serves a radio button.

    
17.03.2016 / 13:31