Skip to content Skip to sidebar Skip to footer

How To Make If Statement For A Specific Image Source?

I have this line in my program (Run in Dreamweaver) which is the following: function go() { if((document.test.test1.src == document.test.test2.src && document.test.test2.sr

Solution 1:

Inside your if statement, you can place a switch/case block to test which image it is of 'x', 'y', etc. It doesn't matter which image's src you check, since you've already checked that they are all equal.

i.e.

if((document.test.test1.src == document.test.test2.src && document.test.test2.src == document.test.test3.src ))
    switch (document.test.test1.src) {
        case "x":
            // Do stuff
            break;
        case "y":
            // Do other stuff
            break;
    }

Solution 2:

if i understand you correctly, within your code you could add a switch e.g.

switch (document.test.test1.src) {
      case 'y':
        ........
        break;
      case 'x'
        ........
        break;
}

"........" designates what you want to run if the object equals y or x respectively.


Solution 3:

This should be fairly simple to implement

var a=document.test.test1.src;
var b=document.test.test2.src;
var c=document.test.test3.src

var fn: {
    x: function() { alert(messageX); },
    y: function() { alert(messageY); },
    z: function() { alert(messageZ);}
};

if(a==b && b==c) {
    if(fn.hasOwnProperty(a)) {
        fn[a](); //you can also use 'b' or 'c' since they're all equal 
    }
}

Post a Comment for "How To Make If Statement For A Specific Image Source?"