Note that there are some explanatory texts on larger screens.

plurals
  1. POCompare variables in Javascript
    primarykey
    data
    text
    <p>I have a script that takes in the value of input tags on a click event and I need to compare them to see if they are the same value. Iam still learning Javascript and JQuery so I really need to find some help. Here is my code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"&gt; &lt;/script&gt; &lt;script&gt; $(document).ready(function(){ $("#swapCard_0").click(function(){ var phpval = document.getElementById('swapCard_0').value; }); $("#swapCard_1").click(function(){ var phpval = document.getElementById('swapCard_1').value; }); $("#swapCard_2").click(function(){ var phpval = document.getElementById('swapCard_2').value; }); $("#swapCard_3").click(function(){ var phpval = document.getElementById('swapCard_3').value; }); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;input type="image" id="swapCard_0" src="image/image0.jpg" value="0"&gt; &lt;input type="image" id="swapCard_1" src="image/image1.jpg" value="1"&gt; &lt;input type="image" id="swapCard_2" src="image/image2.jpg" value="0"&gt; &lt;input type="image" id="swapCard_3" src="image/image3.jpg" value="1"&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>So Say a user clicks image 0 and then clicks image 2 which both have the value of 0, how can I compare them in the function then execute more code? I am sure I would need an if statement but I am not sure how to properly test it in my code. I would like to play a sound when the user clicks two different images that have the same value.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload