I have been trying to work what I am sure is an easy, straightforward solution to having groups of radio buttons tracked for state changes. Here is one such group:
<div class="formRowDiv">
<label><span>TLan:</span></label>
<label>
<input type="radio" id="tlanYes" name="tlan" value="tlanYes"
<?php
if ( $inputValArr[ 'tl' ] == "1" ) {
echo ' checked';
}
?>
>
<span class="radioLabel">Yes</span>
</label>
<label>
<input type="radio" id="tlanNo" name="tlan" value="tlanNo"
<?php
if ( $inputValArr[ 'tl' ] == "0" ) {
echo ' checked';
}
?>
>
<span class="radioLabel">No</span>
</label>
<script>
$(document).ready(function() {
$("input:radio[name='tlan']:checked").change(function() {
if ($("input[name='tlan']:checked").val()=='tlanNo') {
alert( 'tlan: No' );
} else if ($("input[name='tlan']:checked").val()=='tlanYes') {
alert( 'tlan: Yes' );
} // close IF
}); // close anon FUNC .change
}); // close anon FUNC doc.ready
</script>
</div><!-- close formRowDiv -->
The form has its input values initially determined by retrieving them from mySql query ().
If the value initially set by a mySql query is 0 and so "No" (value="tlanNo"), then when the user clicks to changes the field to "Yes," the alert fails to fire, and when I look at the page's source it is the "no" button that is still checked.
When the "no" button is selected, changing from the previously selected "Yes," then the alert fires, and the page source shows that it is (still?) the "No" button that is checked.
I want to eventually save the button's changed state to the page's $_SESSION array. Why then would the change to the non-initially set button value not be registering, and so firing the alert as well as reflecting the change in the page's source after the change has been made, but a change "back" to the initial state seems to get registered?
BTW: I do have the current jQuery lib located in html.php's dir and referenced in the page's header like so:
<script type="text/javascript" src="jquery-3.2.0.min.js"></script>
The :checked selector works for checkboxes, radio buttons, and options of select elements.
$("input:radio[name='tlan']").change(function() { ...
instead of
$("input:radio[name='tlan']:checked").change(function() { ...