Hi all,
I am starting to learn javascript and I had a quick question. I know actionscript and java, so this my mistake here is probably context…but I cant seem to figure it out. I’m trying to figure out how to create a conditional statement based on what button a user clicks. Here’s my code:
[SIZE=”4″]HTML
<h2>What is 1+1?</h2>
<input type=”button” value=”4″ onClick=”answer()”>
<input type=”button” value=”7″ onClick=”answer()”>
<input type=”button” value=”2″ onClick=”answer()”>
<input type=”button” value=”1″ onClick=”answer()”>
[SIZE=”4″]Javascript
<script type=”text/javascript”>
function answer()
{
if(this.value=”2″)
{
alert(“Correct!”);
}
else
{
alert(“Incorrect!”);
}
}
</script>
This doesn’t seem to work. Am I referencing this.value incorrectly? If so, what’s the proper way to get information about what the user clicked?
Thanks so much in advance,
Ben