2

Below code is html produced from opencart 2

No radio button is selected when loading page.

How can i have selected the Value="2" as default checked. (javascript or CSS)

<div id="payment-custom-field1" class="form-group custom-field" data-sort="0">
<label class="control-label">Invoice</label>
<div id="input-payment-custom-field1">
<div class="radio">
<label>
<input type="radio" value="2" name="custom_field[1]">
Receipt
</label>
</div>
<div class="radio">
<label>
<input type="radio" value="1" name="custom_field[1]">
Invoice
</label>
</div>
</div>
</div>

Solution with javascript

(function() {
document.getElementsByName("custom_field[1]")[0].checked=true;
})();
Athon
  • 31
  • 7

3 Answers3

0
<input type="radio" id="sample" value="2" name="custom_field[1]">
Receipt
</label>

Using javascript:

document.getElementById("sample").checked = true;

Using html: You can simply add checked attribute to your html element

Using the element name:

(function() {
   document.getElementsByName("custom_field[1]")[0].checked=true;
})();

https://jsfiddle.net/pandiyancool/vb73q59w/

Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87
0

You can simply add checked attribute

<input type="radio" value="2" name="custom_field[1]" checked>

Sooraj
  • 9,717
  • 9
  • 64
  • 99
0

The solution with javascript was the below code:

document.getElementsByName("custom_field[1]")[0].checked=tru‌​e;

Thank you Pandiyan Cool

Athon
  • 31
  • 7
  • You don't have repost the answer! it will create duplicates. You can click the tick symbol next to the original answer itself which helps you – Pandiyan Cool Sep 06 '16 at 13:28