Friday, 15 May 2015

javascript - How to disable and enable a radio button at the same time -


I have some radio buttons that are displayed from the mysql database. What I'm trying to achieve, when I When I click on the submit button after selecting a radio button, it is disabled and when I click on another radio button, the first disabled one will be enabled and the currently selected radio button will be disabled. My code:

  & lt; Form action = "" & gt; & Lt ;? Php foreach ($ sql- & gt; result () as $ sql) {? & Gt; & Lt; Input type = "radio" name = "session_id" id = "cur" value = "& lt ;? Php echo $ sql-> ID;; & gt;" & Gt; & Lt ;? Php echo $ sql-> Title;? & Gt; & Lt ;? Php}? & Gt; & Lt; Input type = "submit" value = "submit" onclick = "set_type ('a')" & gt; & Lt; / Form & gt; & Lt ;? Php}? & Gt;  

I tried to enable or disable some radio buttons on jsfiddle but it only works with different IDs, whereas my radio button has only one id

Edit : It has been clarified that the ID should be unique. I have changed it.

Whatever I'm actually trying to do, I'm a little confused, but I You will be able to get this code without using attributes:

id or name without attributes. / P>

Approach # 1: Use this code if you want the button to be disabled when the related button button is selected:

  $ (":": "(": ") (": "($" (": Submit"). (": Submit: Disabled"). Prop ("disabled", false); $ (This) .next (": submit"). ("Disabled", true);});  

approach # 2: The latter should only be disabled, then use this code:

  $ (": radio"). ("Change", function () {$ (": submit: disabled") .prop ("disabled", gal );});  

.

Explanation: Basically, whenever you click on a radio Turn on the button, you want to turn the disabled property of currently disabled buttons ... the easiest way to do this is to select all disabled buttons and disable Change the property. After this is done, you can re-apply the disabled status to anyone associated with the radio button (or, What to do when the button is clicked ... whoever you are trying to complete :)).

Note: Also assume that you do not have any other radio buttons and submit buttons on the page. . If you do, then you will need "select" jQuery selectors. The easiest way to do this is to have your & lt; Form & gt; To return the code element and id (I will use "FORM_ID" for this example) and then update the code (": radio") ("Change", Search (": Submit:": "submit" (": submit"). Prop ("disabled", false); $ (this) .next (": submit"). Prop ("disabled ", True);});


Edit:

Based on your explanation, this code should be completed What you are searching for:

<("disabled", false); $ (this) .prop ("" "(Submit: disabled") ("click", function () {$ (": Submit Do: disabled "disabled", true);});

No comments:

Post a Comment