javascript - Where am i Going wrong in this php script to manipulate a string based on radio input

Hi I'm trying to create a small program to
change a string based on a HTML radio input, Think I've got the basics of it complete but not sure I'm doing it the correct way, I'm trying to use a PHP switch but do not know which part I am supposed to attach the switch to. Currently its trying to grab the fieldset, and switch based on the radio options set within that switch.

my PHP code is below:

<!doctype html>
<html>
  <head>
     <title>String Alteration</title>
     <link rel="stylesheet" type="text/css" href="main.css"/>
     <link rel="preconnect" href="https://bit.ly"/>
     <link rel="preconnect" href="https://port-80-ywfrg4rd7y.treehouse-app.com"/>
  </head>
  <body>
    <form class="string_form" width="720" height="120">
      <div class="span_container">
       <span class="numbers_span">
         Please input a String<br>
         into the text field Below.
        </span>
      </div>
      <div class="psuedo_input_outter">
          <input name="InitialString" type="text"
                 minlength="2" maxlength="255" value="" required>
      </div>
            <fieldset name="StringOperator">
              <label for="Option1_TransformUpperCase"
                     class="Numbers_label">Transform To<br>Upper Case</label>
                <input type="radio" name="rad0" value="UpperCase"><br>
              <label for="Option2_TransformLowerCase"
                     class="Numbers_label">Transform To<br>Lower Case</label>
                <input type="radio" name="rad1" value="LowerCase"><br>
              <label for="Option3_FirstCharUpperCase"
                     class="Numbers_label">First Charater<br>Upper Case</label>
                <input type="radio" name="rad2" value="FirstChar"><br>
              <label for="Option4_AllWordsFirstUpperCase"
                     class="Numbers_label">First Charater<br>All words Upper Case</label>
                <input type="radio" name="rad3" value="AllFirstChar"><br>
            </fieldset>
          <button type="submit" id="No_Submit"
                  name="Submit" class="number_challenge_submit">Submit</button>
    </form>
    <?php
      error_reporting(E_ALL);
      session_start();

      $_initialString;
      $_outputString;
// ::>> Notes:           !!>>> Why does HTML attribute checked="true" not move onto the new radio when a different one is selected?
// ::>> Notes:
      if(isset($_GET['Submit'])){
        if(isset($_GET['InitialString'])){
                 $_initialString = $_GET['InitialString'];
           $ToUpperCase    = false;
           $ToLowerCase    = false;
           $FirstCharUpper = false;
           $AllFirstUppper = false;
           $stringOperator = isset($_GET['StringOperator']);
          switch($stringOperator){
            case "rad0":  // Not sure these are correct check them on SO, w3school..
               $ToUpperCase = true;
               $newStr = strtoupper($_initialString);
               echo "<span class='result'>" . $newStr . "</span>";
            break;
            case "rad1":
               $ToLowerCase = true;
               $newStr = strtolower($_initialString);
               echo "<span class='result'>" . $newStr . "</span>";
            break;
            case "rad2":
               $FirstCharUpper = true;
            break;
            case "rad3":
               $AllFirstUpper = true;
               echo ucwords($_initialString);
            break;
          
          }
        // Need to create a check to see which radio button is set.
        // Atleast one of the radio buttons needs to have the html attrib required
        // Use javascript to move this attrib around, based on user select then add attrib 
                                                                 // disabled to all others
          

          // substr_replace($_initialString);
          
          // Need strtoupper();
          // Need strtolower();
          // Need ucwords();
          // Need lcfirst();
          
          // Need to bind these to the radio buttons and use
          //      javascript to disable any none selected radio's
          
        } // 2nd if();             
      }   // 1st if();
     ?>
  <script src="/Js/numbersJs.js" charset="utf-8"></script>
  </body>
</html>

JS

console.log('numbers linked ok..');
document.addEventListener("DOMContentLoaded",function(e){
   let qSAll =(s)=>{
       return document.querySelectorAll(s);
   }
   
   let radioBtns = qSAll('input[type=radio]');
  
   if(radioBtns){
      // ::>> console.trace(radioBtns);
      for(var i=0;i<radioBtns.length;i++){
          if(radioBtns[i].checked == true){
             console.log(radioBtns[i].value);
          }
      }
   }   
   console.log(radioBtns);
  
   //if(radioBtns[0]){
   // console.log('checked');
   //}
});

CSS

.string_form{
  overflow:hidden;
  /* min-width:calc(748px + 2.2vw); */
  /* max-height:calc(438px + 0.85vh); */
  }
.span_container{
  background:linear-gradient(-33deg,#cdcecc,white,gold);
  border-radius:4px;
  user-select:none;
  }
.numbers_span{
  font-size:calc(12.2px + 1.23vw + 0.234vh);
  padding:1px 18px 1px 18px;
  font-family:'Knights Templar', sans-serif;
  border-radius:4px;
  }
input[type=text]{
  position:relative;
  width:411px; max-width:411px;
  transform:translateX(-52px);
  padding:0 2px 0 2px;
  border-radius:4.8px;
  }
input[type=radio]{
  position:relative;
  margin-bottom:calc(28px + 0.08vh);
  max-width:14px;max-height:14px;
  transform:translateX(-174px) translateY(25.8px);
  }
.Numbers_label{
  clear:both;
  float:left;
  background:linear-gradient(-33deg,rgba(242,213,162,0.7),gold);
  padding:4px 9.2px 4px 9.2px;
  font-family:'Knights Templar',sans-serif;
  user-select:none;
  border-radius:9px;
  border-bottom-right-radius:2.1px;
  margin-bottom:4px;
  }
.numbers_label::before{
  display:block;
  position:relative;
  left:-42px;
  width:25px; height:25px;
  background:orange;
  }
.result{
  position:absolute;
  z-index:555;
  top:65%; left:50%;
  transform:translate(-50%,-50%);
  padding:8.2px;
  background:linear-gradient(-32deg,green,gold,orange);
  }

Also want the javascript to disable all other radio buttons when one is selected but can't seem to figure that part out, can anyone give me some pointers so I'm heading in the right direction..

All the answers I have looked at for disableing radio inputs are using JQuery, and when I have tried to translate that inot vanilla javascript it ends up not working..

Just noticed a mistake thatt I've made none of the labels creespond to any Ids, so now changing that part out.. But can anyone give me any php pointers ...

in my javascript code i have got the following script so far, attempting to add checked in the HTML DOM to the selected radio & remove the checked attribute for any radio's that are not the current selected item.

   radioBtns = qSAll('input[type=radio]');
  
   if(radioBtns){
     let Btn;
      // ::>> console.trace(radioBtns);
      for(var i=0;i<radioBtns.length;i++){
        radioBtns.forEach(function(){
            this.addEventListener("click", function(e){
              // Change e.target to checked.
              e.target.setAttribute("checked", "true"); 
              // checked="false" 4 all others..
              let prevRad = e.target.previousElementSibling;    // [contains(@class, 'rad')];
              console.log(prevRad);
              prevRad.removeAttribute("checked");
            })
      }
}

the problem with this is that e.target.previousSibling &or nextSibling returns the html element <br> if i try to use previousElementSibling it is returning the label. not the next radio input up or down in the list..

is there an easier way to de-select the not current/active/used radios & why is this not the default behaviour in the devtools console.. radio stays checked in the markup when selecting another radio even if visually on the screen it is not selected...

Answer

Solution:

Your syntax is wrong here. First of all you should set the name of each radio button same and the value should be used in switch case like UpperCase, LowerCase.

You are actually using the name of the radio button as switch case thats why the click on the radio doesn't work

Source