Linking radio butttons to dropdown menu


I was hoping to complete this little project without using any if/else/while/for/ whatever control flow statements and in just plain javascript but I seem to run into problems. I am just looking to connect the radio buttons to the drop down menu so that when one is clicked, the other is highlighted. For instance, right now I hae it so that when you select an item from the drop down menu using the setRB() function, it sets true the corresponding radio button.



I'd now like to get the radio button to set true to the corresponding dropdown menu item. Can this be done with the conditions above or do I need to use control flow statements (I believe that's what they're all called).



Thanks.



Yes, it is possible.



Access option with the selected option value:



document.querySelector("option[value='x']")





To connect your Select to Radio buttons - and vice versa, you could do like:





The above uses ES6 syntax, Sun kindly provided a ES5 version you can find in this jsFiddle link






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

眉山市

清晰法令