- The World's Best Insult Generator(Gooseylucy)
- Alfie Likes Cheese (alfielikescheese)
- Dogedraw Nyaanhacks
Some javascript to pick random things from an array, and replace a tag ({{name}}
) in it with the text from a text box.
Note: You will nee jQuery for this to work. If you don't already, make sure you add <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
to your <head>
<script>
var things = [
"Random thing 1 {{name}}",
"Random thing 2 {{name}}",
"Random thing 3 {{name}}"
];
function randomThing() {
// Get a random thing from the above array
var thing = things[Math.floor(Math.random()*things.length)];
// If we have a name field
if ($('#name').length) {
// Replace the name tag with the value from the name input box and return it
thing = thing.replace("{{name}}", $('#name').val());
}
return thing;
}
function updateHeader() {
// Update the header with a random thing from teh array above
$('#header').html(randomThing());
}
$(document).ready(function() {
// When we type stuff into the updateText input...
$('#updateHeader').on('input', function() {
// ...update the header with it
$('#header').html($(this).val())
});
});
</script>