简体   繁体   中英

Set up the same radio button after clicking edit

I have a form where I input some data and choose from a group of radio buttons one radio button. Than I click submit and go to the next page where entered data are displayed. On that page I have also buttons Edit and Confirm. When I click edit I return to the next page. I would like that all previously entered information are displayed in the input boxes and that previously chosen radio button is set up too. So I actually was able to set up the same info in the input boxes because I use CDI beans for that. I have a problem with radio button. CDI bean reembers which radio button I choose but when I click Edit button it doesn't mark radio button I choose previously.

So how can I solve this problem? I use simple HTML for the pages and Java code. For your information I don't use JSF. Maybe there are some HTML tricks you could advice me.

I tried to use "checked" for radio button so I know that one radio button will be marked by default but it is not what I want. I choose one particular button and that particular button should be marked when I use "edit" button.

Thank you for your help

So I solved the problem


@Inject 
Controller con; 

String bank = con.getUserBank();

if(bank.equals("BofA")) {
  out.println("<input type=\"radio\" name=\"bank\" value=\"BofA" checked>Bank of America");
} else {
  out.println("<input type=\"radio\" name=\"bank\" value=\"BofA">Bank of America");
}

Now after editing my chosen radio button is marked as previous answer before editing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM