samedi 7 mars 2015

How to make a prompt box input invoke a function?

How do I get rid of the button onclick="clickMe()" and just have the input from the prompt box execute the function?

I need the input from a prompt box to invoke the if statement, i think?



<!DOCTYPE html>
<html>
<head>
<title>Demo</title>
<script>
function clickMe(){
var valueInput=prompt("Please input weekday, weekend?");
var weekdayElement = document.getElementById("weekday");
var weekendElement = document.getElementById("weekend");
if (valueInput=="weekday"){
weekdayElement.style.height = "200px";
weekdayElement.style.width = "250px";
weekdayElement.style.fontSize = "15px";
weekdayElement.style.color="blue";
if (valueInput=="weekend"){
weekendElement.style.height = "200px";
weekendElement.style.width = "250px";
weekendElement.style.fontSize = "15px";
weekendElement.style.color="blue";
}
</script>
</head>
<body>
<h1>This is an example on DOM</h1>
<div id="weekday">
weekdays
<p>Monday</p>
<p>Tuesday</p>
<p>Wednesday</p>
<p>Thursday</p>
<p>Friday</p>
</div>
<div id="weekend">
weekends
<p>Saturday</p>
<p>Sunday</p>
</div>
<p><button onclick="clickMe()">Try it</button></p>
</body>
</html>

Aucun commentaire:

Enregistrer un commentaire