Hello! There is such code that I received from the server and pasted into the body of the page:

<div id="browsers"> <p><b>Браузер:</b><Br> <input type="radio" name="browser" value="ie"> Internet Explorer<Br> <input type="radio" name="browser" value="opera"> Opera<Br> <input type="radio" name="browser" value="firefox" checked="checked"> Firefox<Br> </p> </div> 

In the field with value="firefox" set the parameter checked .

Like in JavaScript (without using jQuery libraries and the like), when you click on another radio button, redefine this parameter?

For example, when you click on input with value="opera" it would set the parameter checked="checked" , and from the previous one, in this case value="firefox" this checked="checked" removed. And so for all radio buttons.

In other words, how you can make the installation of the checked radio buttons dynamically depending on the button press.

Ps I heard that checked by pressing automatically assigns the browser. But in my case, I would like to explicitly establish that in the console (in the elements tab with the source code) you can see the changes in the html code. Thank!

  • "so that the console.log shows changes in the html code." - they are already there. - Igor
  • @Igor I am sorry, not quite correctly expressed. Changes in the console in the Elements tab, where the source code of the page. - Pavel
  • one
    @Pavel as you already said, this property sets the browser and write additional code for the forced update of the DOM, in my opinion, insanity. - XelaNimed September
  • @Xelanimed Do all browsers assign? Could it be that some mobile browser cannot do this? Therefore, for reliability, I would like to install manually - Pavel

1 answer 1

You do not need any JS to change the checked attribute when a client clicks on the radio button in the DOM the checked attribute is updated and the form sends a new value to the server. See for yourself:

http://codepen.io/anon/pen/EgVNrB

Changed the value to Opera , got

 browser: opera 

Concerning

But in my case, I would like to explicitly establish that in the console (in the elements tab with the source code) you can see the changes in the html code.

I think for the sake of it you should not crush