My JS kung fu does not exist, so I seek help. I have a form.php page in which I have about 20 input fields; however, if one radio button is pressed, more than half of these input fields must be disabled. Here is what I still have:
<script type="text/javascript" charset="utf-8">
let fieldsAffected = [ 'f2Cct2Or4Wire2W', 'f2Cct2Or4Wire4W', 'f3Cct2Or4Wire2W', 'f3Cct2Or4Wire4W', 'f4Cct2Or4Wire2W', 'f4Cct2Or4Wire4W' ];
function eqptTypeVal() {
var rs = document.querySelector( 'input[ name = "eqptType" ]:checked' ).value;
if ( rs == '280' ) {
for ( let i = 0; i < fieldsAffected.length; i++ ) {
document.getElementById( fieldsAffected[ i ] ).setAttribute( 'disabled', true );
}
} else {
for ( let i = 0; i < fieldsAffected.length; i++ ) {
document.getElementById( fieldsAffected[ i ] ).removeAttibute( 'disabled' );
}
}
}
window.onload = eqptTypeVal;
$( document ).ready( function() {
$( '#eqptType280' ).click( function() {
for ( let i = 0; i < fieldsAffected.length; i++ ) {
$( fieldsAffected[ i ] ).setAttribute( 'disabled', true );
}
});
});
$( document ).ready( function() {
$( '#eqptType284' ).click( function() {
for ( let i = 0; i < fieldsAffected.length; i++ ) {
$( fieldsAffected[ i ] ).setAttribute( 'disabled', false );
}
});
});
</script>
JS actually works as required, without the fieldsAffected array , using comment blocks in the bottom two JS functions. But since I will have a long list of elementIds to disable, if switch 280 is selected, I want to use an array and a loop to control the disable-enable of the affected elements.
, JS , 280 mysql, , - . 280 284 , JS , elementIds , 280 284 .
2- 3- , , , , , , 280 284 .
JS. - , , , ?
< === HTML === >
<fieldset class="fieldsetToneRemote">
<legend>Eqpt ID</legend>
<div class="formRowDiv">
<label>
<span>Eqpt Type:</span>
<input type="radio" id="eqptType280" name="eqptType" value="280"
<?php
if ( $_SESSION[ 'eqptType' ] == "280" ) {
echo ' checked';
}
?>
>
<span class="radioLabel">280</span>
<input type="radio" id="eqptType284" name="eqptType" value="284"
<?php
if ( empty( $_SESSION[ 'eqptType' ] ) || is_null( $_SESSION[ 'eqptType' ] ) ) {
echo ' checked';
} elseif ( $_SESSION[ 'eqptType' ] == "284" ) {
echo ' checked';
}
?>
>
<span class="radioLabel">284</span>
</label>
</div>