User:Sur/common.js
< User:Sur
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
function storeInput() {
// Get the user's input
var userInput = prompt("Please enter your input:");
// Set the #var with the user's input by embedding it back into the page
if (userInput !== null) {
var variableSyntax = '{{#vardefine: userInput | ' + userInput + '}}';
// Update the HTML element to reflect the user's input
document.getElementById('display').innerHTML = variableSyntax;
// To show what is stored
alert("Stored in #var: " + userInput);
}
}
document.addEventListener("DOMContentLoaded", function() {
var button = document.createElement("button");
button.textContent = "Enter Input";
button.onclick = storeInput;
// Append the button to a specific element or the body
var buttonContainer = document.getElementById('inputButton');
if (buttonContainer) {
buttonContainer.appendChild(button);
} else {
// Fallback if the element doesn't exist, append to body
document.body.appendChild(button);
}
});