Skip to content

Changed button to ask user's name and show smile #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions dom_manipulation/button.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,51 @@
<body>
<button id='squeeze'>Squeeze me</button>

<form id='MessageForm' onsubmit="return processForm()">
<label for="name">Enter your name:</label>
<input type="text" id="name" required>
<button type="submit">Submit</button>
</form>

<img id="Smile" src="images/smile.jpg" alt="A yellow smiley face" />
<p id="Welcome message"></p>

<script>
let button = document.getElementById("squeeze");
function shout(){
alert("... and I squeak");
}
button.addEventListener("click", shout);

let button = document.getElementById("squeeze");
let form = document.getElementById("MessageForm")
let smileImage = document.getElementById("Smile")
let welcomeMessage = document.getElementById("Welcome message")

function onLoad(){
form.hidden = true
smileImage.hidden = true
console.log("Hello world")
}

function shout(){
form.hidden = false
smileImage.hidden = true
button.hidden = true
welcomeMessage.textContent = ""
button.textContent = "Squeak"
alert("... and I squeak");
}
button.addEventListener("click", shout);

function processForm(){
`Get the name they entered`
let name = document.getElementById("name").value

form.hidden = true
button.hidden = false
welcomeMessage.textContent = "Hello " + name + "!"
smileImage.hidden = false

return false; `prevent the page from refreshing`
}

window.onload = onLoad;
</script>
</body>
</html>
Binary file added dom_manipulation/images/smile.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.