How to make a radio button that replaces a specific line in the script. There is a script that, when clicked, replaces the text, so the radio button is needed to change this very line to another. The site has a few buttons. When you click on the text that appears. In the text there are words that need to be changed by radio buttons. As you know js consists of lines there is a line with this word, if you change this line to another, when you press the button, the text with the word that is changed will be displayed.

I mean the string, the string, var table {'the string that needs to be changed' 'one more line that needs to be changed by its radio group', etc. before closing}

    1 answer 1

    Maybe you meant it.

    function chs(strval){ document.getElementById('text').innerHTML = strval; } 
     <p id="text">Яблоко</p> <input type="radio" id="rad2" name="rad" checked onclick="chs('Яблоко')"> <input type="radio" id="rad" name="rad" onclick="chs('Апельсин')"> 

    • I'm sorry I'm not even a novice yet, but can I set an id on a string in js? Don't kick my feet I will learn sometime - Bagdaulet Sayin
    • or you can use the comment line instead of id - Bagdaulet Sayin
    • I mean a string, a string, a var table {'a string that needs to be changed' 'another line that needs to be changed by its radio group', etc. before closing} - Bagdaulet Saiyn
    • For strings it is impossible, but you can put it in the <span id = "elementId"> </ span> tag - ishidex2
    • one
      glad that helped .. or did not help =) - ishidex2