switch statement not recognizing the input

DrDoom :

I've got a switch statement which does not recongize the inputs. It always returns the default one...

As you can see, I have added onclick="rewrite("value")" as well as value inside the input filed.

I have a few other switch statements which work, so I'm really scratching my head over here...

As I have nothing else to add, I'm just adding text over here so it will let me submit.

Any help would be welcome.

<div>
    <input type="image" value="sl" class="zastave" src="assets/drzave/Slo.png" onclick="rewrite('sl'); setInputs('sl');">
    <input type="image" value="en" class="zastave" src="assets/drzave/Ang.png" onclick="rewrite('en'); setInputs('en');">
    <input type="image" value="de" class="zastave" src="assets/drzave/Nem.png" onclick="rewrite('de'); setInputs('de');">
    <input type="image" value="it" class="zastave" src="assets/drzave/Ita.png" onclick="rewrite('it'); setInputs('it');">
    <input type="image" value="hr" class="zastave" src="assets/drzave/Hrv.png" onclick="rewrite('hr'); setInputs('hr');">
    <input type="image" value="ru" class="zastave" src="assets/drzave/Rus.png" onclick="rewrite('ru'); setInputs('ru');">
</div>
function rewrite(){
    let smol = document.getElementById("small");
    let advT = document.getElementById("adv-t");
    let advC = document.getElementById("adv-c");
    let a = document.getElementById("a");
    let d = document.getElementById("d");
        switch (rewrite){
            case "sl":
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'Do you want to recieve our emails?';
                advC.innerHTML = 'Yes, send me emails.';
                smol.innerHTML = 'I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'Agree';
                d.innerHTML = 'Disagree';
                break;
            case "en":
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'X Do you want to recieve our emails?';
                advC.innerHTML = 'X Yes, send me emails.';
                smol.innerHTML = 'X I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'X Agree';
                d.innerHTML = 'X Disagree';
                break;
            case "de":              advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'Y Do you want to recieve our emails?';
                advC.innerHTML = 'Y Yes, send me emails.';
                smol.innerHTML = 'Y I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'Y Agree';
                d.innerHTML = 'Y Disagree';
                break;
            case "it":
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'Z Do you want to recieve our emails?';
                advC.innerHTML = 'Z Yes, send me emails.';
                smol.innerHTML = 'Z I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'Z Agree';
                d.innerHTML = 'Z Disagree';
                break;
            case "hr":              
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'XX Do you want to recieve our emails?';
                advC.innerHTML = 'XX Yes, send me emails.';
                smol.innerHTML = 'XX I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'XX Agree';
                d.innerHTML = 'XX Disagree';
                break;
            case "ru":              
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'XY Do you want to recieve our emails?';
                advC.innerHTML = 'XY Yes, send me emails.';
                smol.innerHTML = 'XY I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'XY Agree';
                d.innerHTML = 'XY Disagree';
                break;
            default:                
                advT.innerHTML = '';
                advC.innerHTML = '';
                smol.innerHTML = '';
                a.innerHTML = '';
                d.innerHTML = '';
                advT.innerHTML = 'XZ Do you want to recieve our emails?';
                advC.innerHTML = 'XZ Yes, send me emails.';
                smol.innerHTML = 'XZ I agree to whatever you say. We don`t read small print';
                a.innerHTML = 'XZ Agree';
                d.innerHTML = 'XZ Disagree';
                break;
            }
};
Tim Biegeleisen :

You never defined your rewrite() on click handler function to accept an input parameter. You should do that, and then switch on this value:

function rewrite(value) {
    // ...
    switch (value) {
        case "sl":
            advT.innerHTML = '';
            // etc.
            break;

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27224&siteId=1