0

Hi please help me with below question

I’m working on jsp, I have situation like in that jsp we are using spring form tags, my task is to create two radio buttons when user click on radio buttons I need to display different options and I need to send user opted radio button value to my controller.

  1. I wrote form:radiobutton but this is not accepting onclick/onchange attribute to call my JavaScript..!!!

2.So I wrote input tag where I can use this to call my js — with this I cant send value to controller, if I want to I can get the value from request attribute from session but I don’t want to disturb the code structure where everything coming from form tags to backend controller.

We are using jsp,spring mvc with out annotated , servlets, java8, wi

So I’m confused how to serve my purpose... please explain me thanks for your time.👍🏻

1 Answer 1

0

<form:radiobutton path="test"> (for example) will set the name of the generated input element to "test". You can thus use document.querySelectorAll to select all the radio buttons with the same name. Then, loop over them and use addEventListener on each one.

for(const radio of document.querySelectorAll('input[type=radio][name="test"]')){
    radio.addEventListener("change", function(e){
      // do something on change
    });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.