<label for="name">Name: </label><input id="name" type="text" /><br /><br />
<label for="name">City: </label><input id="city" type="text" /><br /><br />
<button id="submit">Submit</button>
<button id="capitalize">Capitalize Everything!</button>
<button id="clear">Clear</button>
<p>
Your Name is <span id="outputName">____</span>. The city in which you live is <span id="outputCity">____</span>.
</p>
CSS
#outputName, #outputCity{
color: red;
}
JavaScript
var submit = document.getElementById("submit");
var capitalize = document.getElementById("capitalize");
var clear = document.getElementById("clear");
submit.onclick = function(){
var name = document.getElementById("name").value;
var city = document.getElementById("city").value;
document.getElementById("outputName").innerText = name;
document.getElementById("outputCity").innerText = city;
}
capitalize.onclick = function(){
var name = document.getElementById("name").value;
var city = document.getElementById("city").value;
document.getElementById("name").value = name.toUpperCase();
document.getElementById("city").value = city.toUpperCase();
}
clear.onclick = function(){
document.getElementById("name").value = "";
document.getElementById("city").value = "";
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.