Skip to content

Instantly share code, notes, and snippets.

@unisys12
Last active December 12, 2015 01:08
Show Gist options
  • Save unisys12/4688951 to your computer and use it in GitHub Desktop.
Save unisys12/4688951 to your computer and use it in GitHub Desktop.
My first JavaScript experiment. Since I am currently learning JavaScript, this was my first - "I wonder if I can do that?" moment. So, it's nothing special.
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>JavaScript Form Fill</title>
<meta name="viewport" content="width=device-width">
<style>
ul li {
list-style: none;
}
</style>
</head>
<body>
<div class="main">
<form action="" id="form">
<fieldset>Enter Your Name</fieldset>
<ul>
<li><label for="fName">First Name: </label></li>
<li><input type="text" id="fName" onchange=fNameInput(this.value) ></li>
<li><label for="lName">Last Name: </label></li>
<li><input type="text" id="lName" value=""></li>
<li><label for="age">Age: </label></li>
<li><input type="number" id="age" value=""></li>
</ul>
</form>
</div>
<script>
var person = [];
function fNameInput(fName)
{
var fName = prompt("What is your first name?");
if(fName)
{
person.push(fName);
document.getElementById('fName').value = fName;
}
else
{
fName = prompt("You have to give me your first name!");
person.push(fName);
document.getElementById('fName').value = fName;
}
}
function lNameInput(lName)
{
var lName = prompt("And what is your last name?");
if(lName)
{
person.push(lName);
document.getElementById('lName').value = lName;
}
else
{
lName = prompt("You are truly being difficult about this!");
person.push(lName);
document.getElementById('lName').value = lName;
}
}
function ageInput()
{
var age = prompt("Last, but not least... What is your age?");
if(age)
{
person.push(age);
document.getElementById('age').value = age;
}
else
{
age = prompt("Ok, your just being an ass now! What is your age?");
person.push(age);
document.getElementbyId('age').value = age;
}
}
function gatherInfo()
{
fNameInput();
if(fNameInput)
{
console.log("You got the first name. Sweet!");
}
else
{
alert("You have a problem with your code!");
}
lNameInput();
if(lNameInput)
{
console.log("You got the last name. Sweet!");
}
else
{
alert("You have a problem with your code!");
}
ageInput();
if(ageInput)
{
console.log("You got the age too. Sweet!");
}
else
{
alert("You have a problem with your code!");
}
}
gatherInfo();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment