keeping radio buttons checked after form submit

后端 未结 2 1928
一个人的身影
一个人的身影 2020-12-20 00:44

I have two set of radio buttons in html form button and button1. I am using below code to

1.keep the default value checked (

2条回答
  •  不知归路
    2020-12-20 01:37

    So, the problem is you're setting the checked value twice upon form submission, resulting in selecting either the default value (from initial form state) or the value that has been submitted.

    For this to work correctly, you'd need always use PHP to append the checked value to your radio elements, like this:

    /> />
    /> />

    Here's a working preview: http://codepad.viper-7.com/rbInpX

    Also, please note that you're using inline JavaScript notation which is normally discouraged to keep dynamic JS content separate and more manageable ;-)

提交回复
热议问题