0 votes
in SoSci Survey (dt.) by s109993 (10.3k points)
closed by s109993

Das ist in einer Mehrfachasuwahlskala, in der es die Otion "andere" gibt, mit einem Textfeld. Wenn in der Skala eine Ausweichoption angeklickt wird, soll das Textfeld geleert werden. Und anders herum: wenn etwas in das Textfeld geschrieben wird, soll der radiobutton.checked = false

// Get the checkbox element
const checkbox = document.getElementById('F009_07DK');

// Get the textfield element
const textField = document.getElementById('F012_01');

// Add an event listener to the checkbox
checkbox.addEventListener('change', function() {
    // Check if the checkbox is checked
    if (this.checked) {
        // Clear the textfield
        textField.value = '';
    }
});

Das ist die idee- die leider nicht funktioniert. Kann es an der Ausweichoption oder Mehrfachauswahl liegen?

Answer:

<script>


// Get the checkbox element
const checkbox = document.getElementById('F009_07DK');

// Get the textfield element
const textField = document.getElementById('F012_01');

// Add an event listener to the checkbox
checkbox.addEventListener('click', function() {
    // Check if the checkbox is checked
    if (this.checked) {
        // Clear the textfield
        textField.value = '';
    }
});


// Add an event listener to the checkbox
textField.addEventListener('input', function() {
    // Check if the text field is filled
    if (this.value.trim() !== '') {
        // Unselect the radio button
        checkbox.checked = false;
    }
});
</script>
closed with the note: solved
by SoSci Survey (308k points)
Verwenden Sie eine Skala oder eine Mehrfachauswahlmatrix?

Ersetzen Sie das "change" bitte einmal durch "click" - ich bin ziemlich sicher, dass eine Checkbox kein "change" kennt.
by s109993 (10.3k points)
Es ist eine Mehrfachauswahlmatrix. Mit click funktioniert es. Wie würde ich die Umkehrbedingung schreiben? Ein neues html Feld, die cons wieder definieren und dann die Schlaufe einfach umdrehen?

// Get the checkbox element
const checkbox = document.getElementById('F009_07DK');

// Get the textfield element
const textField = document.getElementById('F012_01');

// Add an event listener to the checkbox
textField.addEventListener('input', function() {
    // Check if the text field is filled
    if (this.value.trim() !== '') {
        // Unselect the radio button
        radioButton.checked = false;
    }
});
by SoSci Survey (308k points)
> Es ist eine Mehrfachauswahlmatrix.

Es ist auch beabsichtigt, dass mehrere Optionen pro Zeile gewählt werden dürfen? Ich frage nur zur Sicherheit, weil der Fragetyp manchmal mit einer Skala verwechselt wird - und das "radioButton" in Ihrem Code deutet darauf hin, dass Sie evtl. einfache Auswahlpunkte erwartet hätten.

> Wie würde ich die Umkehrbedingung schreiben?

Um das Textfeld zu überwachen, empfehle ich das "keyup"-Event.
by s109993 (10.3k points)
Ja, leider möchte das der Kunde so... Danke!

Willkommen im Online-Support von SoSci Survey.

Hier bekommen Sie schnelle und fundierte Antworten von anderen Projektleitern und direkt von SoSci Survey.

→ Eine Frage stellen


Welcome to the SoSci Survey online support.

Simply ask a question to quickly get answers from other professionals, and directly from SoSci Survey.

→ Ask a Question

...