+ 2

How to get the input radio to work?

I know that if you give the yser a choice you need to write <input type="radio"/>. But now I want the selection the user chose to automatically, let's say, calculate something which he wouldn't have gotten if he had chosen the other radio button. How do I achieve that?

20th Sep 2017, 3:53 PM
zig_zag_z
zig_zag_z - avatar
6 ответов
+ 2
It better be done on client side using Javascript. Check out this code, use Javascript to condition the other inputs based on radio selected input. https://code.sololearn.com/Wg0znSMd76kD/?ref=app
20th Sep 2017, 4:12 PM
Calviղ
Calviղ - avatar
+ 1
Ok thanks both of you
20th Sep 2017, 4:13 PM
zig_zag_z
zig_zag_z - avatar
+ 1
Although it might be better in javascript (Im not sure as I dont know much JS yet) it is also possible to prevent multiple selection with just html by using the name attribute to link them. For example, adding a name attribute of "gender" to 2 radio fields would stop you from selecting both. (Im assuming this is the problem you're having) This may be useful https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/radio
20th Sep 2017, 6:15 PM
JoeJoe
+ 1
Thanks a lot
20th Sep 2017, 6:25 PM
zig_zag_z
zig_zag_z - avatar
0
if youre just using JS then you can use the onchange event
20th Sep 2017, 4:02 PM
Enzo
Enzo - avatar
0
Do you have to use JS? Haven't done that yet. Learning JS on my to-do-list :)
20th Sep 2017, 4:07 PM
zig_zag_z
zig_zag_z - avatar