JSFiddle - React, Tailwind, and code Playground

by Joulence

HTML

<input type="radio" name="trade" value=l>1<br> 
<input type="radio" name="trade" checked value=2>2<br>
<label><input type="radio" name="trade" id="long" checked value="long"> Long</label>

                <label><input type="radio" name="trade" id="short"> Short</label>
<label><input type="radio" name="trade" value=3>3<br></label>
<hr/>
<input type="button" value="check" onclick="check()" />
<br/>
<input type="button" value="check jQuery" onclick="check2()" />

JavaScript

function check()
{
    var inp = document.getElementsByName('trade');
    for (var i = 0; i < inp.length; i++) {
        if (inp[i].type == "radio" && inp[i].checked) {
            alert("selected: " + inp[i].value);
        }
    }
}

    
    function check2()
    {
        alert("selected: " + $('input[name=trade]:checked').val());
    }