0

I have this select option:

<div class="okreci_select">
        <select onchange="changeImage(this)" id="selectid">
         <option value="samsung">Samsung</option>
         <option value="apple">Apple</option>
         <option value="lg">LG</option>
         <option value="htc">HTC</option>
        </select>
</div>

And I have this js function:

function changeImage(el) {
    if (el.value == "samsung"){
      document.getElementById("IzabranUredjajSl").src = "Slike/uredjajSamsung.png";
      document.getElementById("prom_vr_kara").innerHTML = "- 5.1” / 2560x1440 ekran <br/> - 12 MP / 5 MP kamere <br/> - Octa-core / 4 GB platforma <br/> - do 32 GB memorije ";
    }
      else if(el.value == "apple"){
        document.getElementById("IzabranUredjajSl").src = "Slike/uredjajApple.png";
        document.getElementById("prom_vr_kara").innerHTML = "- 4.7” / 1334x750 ekran <br/> - 12 MP / 7 MP kamere <br/> - Quad-core / 2 GB platforma <br/> - do 32 GB memorije ";
    }
}

How can I use the fadein() method when the el.value is equal to something. For example, when the value is apple, I want the uredjajApple.png to fadein. I've tried:

document.getElementById("IzabranUredjajSl").src = "Slike/uredjajApple.png".fadein();

But it doesn't work. Same goes for the text (innerHTML), how do I make them fade in when the el.value changes?

4
  • try adding document.getElementById("prom_vr_kara").fadeIn(1000); after the other two lines of code Commented Dec 4, 2016 at 15:52
  • You mean like this: document.getElementById("prom_vr_kara").fadein(3000) = "texttext"; It doesn't work :( @JonHerbert Commented Dec 4, 2016 at 16:01
  • Well I don't think that would work because you're not setting the correct thing, If you want to change the text then you need to reference the text first. Commented Dec 4, 2016 at 16:09
  • Also if you're going to be referencing those elements a lot I would consider turning them into variables instead Commented Dec 4, 2016 at 16:26

2 Answers 2

0

Try something like this

function changeImage(el) {
    $(el).fadeIn( "slow", function() {
        if (el.value == "samsung"){
          document.getElementById("IzabranUredjajSl").src = "Slike/uredjajSamsung.png";
          document.getElementById("prom_vr_kara").innerHTML = "- 5.1” / 2560x1440 ekran <br/> - 12 MP / 5 MP kamere <br/> - Octa-core / 4 GB platforma <br/> - do 32 GB memorije ";
        }
        else if(el.value == "apple"){
            document.getElementById("IzabranUredjajSl").src = "Slike/uredjajApple.png";
            document.getElementById("prom_vr_kara").innerHTML = "- 4.7” / 1334x750 ekran <br/> - 12 MP / 7 MP kamere <br/> - Quad-core / 2 GB platforma <br/> - do 32 GB memorije ";
        }
    });
}

http://api.jquery.com/fadein/ You may need to play around with the place in which you call the fadein function, perhaps within the if/else statement, sorry don't have the time to check myself. But read the Docs and you should be good to go

EDIT

Reference to this

Sign up to request clarification or add additional context in comments.

3 Comments

Uncaught TypeError: el.fadeIn is not a function @JonHerbery. I'll look around in the docs
try now and if not add an id selector for the function as per the other question referenced
Fixed my problem by adding fadeout before the image changes, then fading in after
0

Fixed my problem by adding fade out before the picture changes then fade in after the picture changes:

function changeImage(el) {
  if (el.value == "samsung"){
    $("#IzabranUredjajSl").fadeOut(1);
    document.getElementById("IzabranUredjajSl").src = "Slike/uredjajSamsung.png";
    $("#IzabranUredjajSl").fadeIn(1000);
    document.getElementById("prom_vr_kara").innerHTML = "- 5.1” / 2560x1440 ekran <br/> - 12 MP / 5 MP kamere <br/> - Octa-core / 4 GB platforma <br/> - do 32 GB memorije ";
    document.getElementById("prom_vr_cena").innerHTML = "- Zvezda | 70 000din <br/> - Sunce | 50 000din <br/> - Gаlаksijа | 30 000din <br/>";
  }
  else if(el.value == "apple"){
    $("#IzabranUredjajSl").fadeOut(1);
    document.getElementById("IzabranUredjajSl").src = "Slike/uredjajApple.png";
    $("#IzabranUredjajSl").fadeIn(1000);
    document.getElementById("prom_vr_kara").innerHTML = "- 4.7” / 1334x750 ekran <br/> - 12 MP / 7 MP kamere <br/> - Quad-core / 2 GB platforma <br/> - do 32 GB memorije ";
    document.getElementById("prom_vr_cena").innerHTML = "- Zvezda | 80 000din <br/> - Sunce | 60 000din <br/> - Gаlаksijа | 40 000din <br/>";
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.