I haven't worked with forms much and am trying to get this form to be able to select more than 1 radio button per time (which it currently can, but you then cannot unselect one if it's already selected) and then submit the rows with radios selected (if that makes sense). And then once a row has been submitted, be then unable to select the radio input for that row.
Not sure why, but the radio buttons that are selected before clicking submit aren't then added the disabled='disabled'
attribute after clicking submit. Does anyone know why? And how can it be fixed?
Thanks for any help here.
function submitForm() {
var radioOne = $("#one"),
radioTwo = $("#two"),
radioThree = $("#three"),
theForm = $("#theForm");
alert('Form will submit');
//theForm.submit();
if (radioOne.checked = true) {
radioOne.attr('disabled','disabled');
}
if (radioTwo.checked = true) {
radioTwo.attr('disabled','disabled');
}
if (radioThree.checked = true) {
radioThree.attr('disabled','disabled');
}
}
div {
display: flex;
flex-flow: row norwap;
align-items: center;
justify-content: center;
border: 1px solid black;
margin-bottom: 10px;
}
button {
margin: 0 auto;
display: block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form id='theForm'>
<div>
<p>Detail 1</p>
<p>Detail 2</p>
<input type="radio" name="one" id="one" value="one" /><label for="one">One</label>
</div>
<div>
<p>Detail 1</p>
<p>Detail 2</p>
<input type="radio" name="two" id="two" value="two" /><label for="two">Two</label>
</div>
<div>
<p>Detail 1</p>
<p>Detail 2</p>
<input type="radio" name="three" id="three" value="three" /><label for="three">Three</label>
</div>
<button onclick='submitForm()'>Submit</button>
</form>