Randomize according to a radio button

0

I want to use "Radio Buttons" in HTML but I do not know how to use them. How do I do them, but I need something like this:

If I use the one option, generate a random word being Language, Language.

If I use option two, generate a random word being Language, Dialect.

I can generate a random word with PHP, I need to know how to "distribute" the two.

    
asked by anonymous 23.08.2015 / 20:39

1 answer

2

Look like this:

<html>
<head>
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script></head><body><scripttype="text/javascript">
$(document).ready(function() {
  $('#radioA').click(function() {
    var data = 'id=aleaa';
    $.get('aleatoria.php', data, function(response){
      $('#dv').html(response);
    });
  });
  $('#radioB').click(function() {
    var data = 'id=aleab';
    $.get('aleatoria.php', data, function(response){
      $('#dv').html(response);
    });
  });
});
</script>

<div id="dv"></div><br/>
<input type="radio" name="group1" value="aleatoria" id="radioA"> aleatório A<br>

<input type="radio" name="group1" value="aleatoria" id="radioB"> aleatório B<br>
<!--<button id="buton">Click</button>-->

</body>

and create a random.php file like this:

<?php
    if($_GET["id"] == "aleaa")
    {
    $palavras = array('Língua','Linguagem'); 
    $aleatorio = rand(0,1); 
    echo $palavras[$aleatorio];
    } 
    elseif($_GET["id"] == "aleab")
    {
    $palavras = array('Idioma','Dialeto'); 
    $aleatorio = rand(0,1); 
    echo $palavras[$aleatorio];
    }
 ?>

jquery makes a GET in the random.php file if the parameter (? id = alea) is correct it takes the random word it generated. If the answers were satisfactory, I ask you to score:)

    
24.08.2015 / 22:24