lundi 24 août 2020

How to create droptown list with selection part and generate the random value?

So right now,there is 4 input text place.You can write everything what you want and when you click the "pick one" button, you gonna get back any text what you entered earlier. I would like change these kind of input text places to the dropdown lists where you can select some teams and when you click "pick one" you gonna get 1 team randomly. <?php

error_reporting(0);

if(isset($_POST['submit']))
    {
        $team1=$_POST['team1'];
        $team2=$_POST['team2'];
        $team3=$_POST['team3'];
        $team4=$_POST['team4'];

        $teams=array
        (
            "1" =>"$team1",
            "2" =>"$team2",
            "3" =>"$team3",
            "4" =>"$team4",
        );
    $random = rand(1, 4);
    }
?>


<html>
<form action="index.php" method="POST">
Enter the team name<input type="text" name="team1" value="<?php echo $team1 ?>"><br>
Enter the team name<input type="text" name="team2" value="<?php echo $team2 ?>"><br>
Enter the team name<input type="text" name="team3" value="<?php echo $team3 ?>"><br>
Enter the team name<input type="text" name="team4" value="<?php echo $team4 ?>"><p>

<input type="submit" name="submit" value="Pick One!"><br>
</form>

<?php

print $teams["$random"];

?>
</html>



Aucun commentaire:

Enregistrer un commentaire