1

I have a webpage that contains two set of radio buttons. I want to do; if user select a OS in first fieldset and a language from second fieldset, then user must directed to relevant pages.

Please guide me to complete this page. I am unable to get two radio button values at a time. If I rename the radio buttons like below,

<fieldset id="group1">
    <input type="radio" class="radto" name="android"/>
</fieldset>
<fieldset id="group1">
    <input type="radio" class="radto" name="english"/>
</fieldset>

It's working, but the problem is users can select more than one OS and language. I need to prevent this. How can I overcome this problem.

<?php
if (isset($_POST['submit'])) {
    if (isset($_POST['android']) && isset($_POST['english'])) {

        header("location: andro_eng.php");
        exit();
}

    if (isset($_POST['android']) && isset($_POST['french'])) {

        header("location: andro_fre.php");
        exit();
    }
}

?>

<html>
<head>
</head>

<body>
<form action="" method="post">
<fieldset id="group1">
    <li><input type="radio" class="radto" name="a"/>&nbsp;   &nbsp;android</li>
    <li><input type="radio" class="radto" name="a"/>&nbsp;   &nbsp;ios</li>
    <li><input type="radio" class="radto" name="a"/>&nbsp;   &nbsp;symbian</li>
</fieldset>

<fieldset id="group2">
    <li><input type="radio" class="radto" name="b">&nbsp; &nbsp;english</li>   
    <li><input type="radio" class="radto" name="b" >&nbsp; &nbsp;french</li>
    <li><input type="radio" class="radto" name="b">&nbsp; &nbsp;spanish</li>
</fieldset>
<input type="submit" value="next" name="submit">
</form>
</body>
</html>
3
  • This is more html than php Commented Feb 17, 2016 at 16:57
  • @Goose this page has more php,but i just showed only the radio button codes. Commented Feb 17, 2016 at 17:08
  • PHP isn't causing the issue. A lot of people can help unfortunately aren't looking at this question because they think it involves PHP and they don't know PHP. Just a helpful tip! Commented Feb 17, 2016 at 17:13

1 Answer 1

1

The name attribute has to be the same for the different options:

$( document ).ready(function() {
  $('#button').click(function() {
    alert($('input[name=os]:checked').val()); 
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<fieldset id="group1">
<input type="radio" class="radio" name="os" value="android" id="android" />
<label for="a">Android</label>
</fieldset>
<fieldset id="group1">
<input type="radio" class="radio" name="os" value="iOS" id="iOS" />
<label for="b">iOS</label>
 </fieldset>

<button id="button" type="button">Get value</button>

And you need to add a value attribute to the radio inputs, otherwise you won't get any value.

Then you can get the values from PHP: $_POST['os'] will return android, iOS or may be empty if no value is selected.

Sign up to request clarification or add additional context in comments.

4 Comments

Check the $_POST["a"] and $_POST["b"] (which are the name property of your radio buttons). They will be filled by the selected value associated to the selected button. You must add the value property to your HTML like : <input type="radio" class="radto" name="b" value="spanish"/>Spanish
@Dom which are the name property of your radio buttons No, the name is android. I have updated the answer in order to provide a better example.
I am sorry, I would like to create a new answer and update yours. Sorry
@Dom feel free to add another answer. I updated my answer to explain how to get a value with PHP.

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.