I'm using cookies to scroll to different sections of a given page. The cookies are saved fine. Only one cookie can exist at a given time. I can see them in the application as they should be. However, there is an issue with my conditionals where only the last if statement runs.
jQuery(document).ready(function ($) {
var internetcsomagcookie = null;
var csomagcookie = "true";
var triocsomagcookie = null;
var tvcsomagcookie = null;
if ((csomagcookie = "true")) {
document.getElementById("csomag").scrollIntoView();
}
if ((triocsomagcookie = "true")) {
document.getElementById("trio").scrollIntoView();
}
if ((internetcsomagcookie = "true")) { document.getElementById("internet").scrollIntoView();
}
if ((tvcsomagcookie = "true")) {
document.getElementById("tv").scrollIntoView();
}
});
#internet,#trio,#tv,#csomag {height:1000px;}
#internet {background:blue;}
#tv {background:red;}
#csomag {background:green;}
#trio {background:orange;}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div id="csomag"></div>
<div id="trio"></div>
<div id="internet"></div>
<div id="tv"></div>
The issue is, that after creating any of the cookies (except for the last one - tvcsomagcookie), whenever I load the page where I want the scrolltoview to happen on, it jumps to the last ID in the code (basically the last if statement executes that scrolls to #tv), despite the tvcsomagcookie returning 'null'. So it runs when it should not.
If statements were originally posted with = (which is for assignment) instead of == for comparison. Updating this inside the code fixed the issue.