Calculator Tools Calculator Tools
Create

Random Country Picker

Dec 19, 2023

About this app

Pick a random country from our database

Random Country Picker Random Country Picker Continent: All Continents Asia Europe North America South America Africa Australia & Oceania Include territories Random Countries

Related apps

Put this on your site

Source

                    <html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1">

<title>Random Country Picker</title>
<meta name="description" content="Pick a random country from our database">
<meta name="keywords" content="random, country, picker, database">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">

<script type="text/javascript">
try {
// App Javascript Goes Here. Place your entire script content inside the try block for error handling.

// This will run when the DOM is ready.
document.addEventListener("DOMContentLoaded", function() {
// Function to handle the random country selection
function getRandomCountry() {
// Get the selected continent
var continent = $("#continent").val();

// Check if territories should be included
var includeTerritories = $("#includeTerritories").is(":checked");

// Call the API to get the random country
$.ajax({
url: "https://random-country-picker-api.com/random/country",
data: {
continent: continent,
includeTerritories: includeTerritories
},
success: function(response) {
// Display the random country
$("#randomCountry").text(response.countryName);
},
error: function(xhr, status, error) {
console.log(error);
}
});
}

// Event listener for the random countries button
$("#randomCountriesButton").on("click", function() {
getRandomCountry();
});
});

} catch (error) {
// This will throw the error to the parent window.
throw error;
}
</script>

<style>
/* App CSS Goes Here */
body {
background-color: #f8f9fa;
font-family: 'Arial', sans-serif;
}

.container {
margin-top: 50px;
}

h1 {
color: #333;
text-align: center;
margin-bottom: 30px;
}

.form-group {
margin-bottom: 20px;
}

.form-check-label {
font-weight: normal;
}

#randomCountry {
margin-top: 20px;
text-align: center;
font-size: 24px;
font-weight: bold;
}
</style>
</head>
<body>
<div id="main-container" class="container">
<h1>Random Country Picker</h1>

<div class="form-group">
<label for="continent">Continent:</label>
<select id="continent" class="form-control">
<option value="all">All Continents</option>
<option value="Asia">Asia</option>
<option value="Europe">Europe</option>
<option value="North America">North America</option>
<option value="South America">South America</option>
<option value="Africa">Africa</option>
<option value="Australia & Oceania">Australia & Oceania</option>
</select>
</div>

<div class="form-group">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="includeTerritories">
<label class="form-check-label" for="includeTerritories">Include territories</label>
</div>
</div>

<button id="randomCountriesButton" class="btn btn-primary">Random Countries</button>

<div id="randomCountry"></div>
</div>
</body>
</html>