Pradip Shenolkar
Pradip Shenolkar

Reputation: 797

Bootstrap: active class

In bootstrap, active class is used to get selected radio button value. When a radio button is clicked, active class is added to label of that button. After submitting the form value of radio button with active label is sent for further processing.

However when the active class is added from jquery and form is submitted, it doesn't post/get value of that button. To make this work I have to simulate the click on radio button with active class.

getValue.php

    $pr_type=$_POST['pr_type'];
    echo "pr_type : ".$pr_type;

Upvotes: 4

Views: 1204

Answers (1)

Kent Anderson
Kent Anderson

Reputation: 486

In order for a radio button value to be sent to the server during a POST request, it must be marked as "checked". You can do this more than one way.

For example:

  1. You can simulate a user clicking on the radio button which will cause the radio button to be selected.
  2. You can mark the radio button checked by setting the "checked" attribute to "checked". See this answer for reference.

Either way should work, but the second method would be preferable. Once the radio button is checked, it can be styled however you like. Use can use the Bootstrap class 'active' or any other that you like, but the styling will have no bearing on what is sent back to the server.

Upvotes: 1

Related Questions