I am in my second semester at SCSU and currently taking an introductory course into Computer Science. We are going over the basics of HTML and Javascript.
The latest lab I worked on was using a button to change a sad face into a happy face. However, I was wondering if it was possible to check if you have already clicked the button, if so, using an If statement it will pop up an alert saying, "You made me smile!"
<html>
<head>
<title>Are you sad?</title>
</head>
<body>
<div style="text-align:center">
<img id="sadFace" src="http://balance3e.com/Images/sad.gif">
<p>
<input type="button" value="Smile"
onclick="document.getElementById('sadFace').src='http://balance3e.com/Images/happy.gif';
alert('You made me smile!');">
</p>
</div>
</body>
</html>
Presently the program will display the alert when I click the button (this was for extra credit). However, I would like to check if the button has already been pressed, if so it will display the alert.
if(document.getElementById('sadFace').src == 'http://balance3e.com/Images/happy.gif'){alert('clicked')}. I hope that answer your question