dimanche 3 décembre 2017

If Argument Defining Variable

It appears as though the argument of my if statement is re-setting the value of the variable I am checking.

I have the following button

<select class="demobutton" id="currencytype" style="padding-left:2.3em;">
<option value="BTC">BTC</option><option value="XMR">XMR</option><option value="LTC">LTC</option><option value="ZEC">ZEC</option><option value="ETH">ETH</option></select>

and use the script

function changeData() {
                    var currency = document.getElementById("currencytype").value;
                    var daterange = document.getElementById("rangecalendar").value;
                    var imp = document.getElementById("impetus").value;     

To extract the input of the button.

Then I analyze that input and modify data presented on the website accordingly.

if (currency = 'btc') {
                        alert(currency);
                        if (daterange = '08/21/17 - 12/03/17') {
                            if (imp = '1H') {
                                document.getElementById('roioutput').innerHTML = '542%';
                                document.getElementById('sharpe').innerHTML = '.403';
                                document.getElementById('alpha').innerHTML = '-.193';
                                document.getElementById('beta').innerHTML = '0.00';
                                $('#graph img').attr('src','images/graph1hbtc.png');
                            }
                        }

                    }

For debugging purposes, I included an alert in the code. When I use the alert to print the value of the variable currency before the if statement in my script, the value is the value in the input button which is what I want. However, the alert in the if statement shows me the value of whatever I am checking the variable against in the argument (in this case 'btc'). It is as though instead of checking if currency = 'btc', the if statement is setting currency = 'btc'.

Why is this and what can be done to prevent it?

If it helps to see my complete code in action, go here

Aucun commentaire:

Enregistrer un commentaire