Code: Select all
< /code>
Aus anderen Gründen füge ich die Attribute "Name" im laufenden Fliegen hinzu. Schließlich dreht sich all das in diesem HTML-Code an: < /p>
< /code>
Wenn ich dann versuche, Werte zu erhalten < /p>
multiple = document.querySelector('input[name="rblMultiple"]:checked').value; //Get "N"
shipping = document.querySelector('input[name="rblShipping"]:checked').value; //Fails. Should get "C", but object is null
< /code>
Dies ist die erste Funktion, die auf ContentPageload ausgeführt wird: < /p>
function prepareForms() {
...
document.querySelectorAll('input[type="radio"][data-name]').forEach(rb => {
rb.setAttribute('name', rb.getAttribute('data-name'));
rb.addEventListener('click', e => radioButtonListValue(e.target));
radioButtonListValue(rb);
var hd = document.querySelector(`input[type="hidden"][id$="hd${rb.getAttribute('data-name')}"]`);
if (hd) rb.checked = (rb.value == hd.value);
});
}
function radioButtonListValue(rb) {
const hd = document.querySelector(`input[type="hidden"][id$="hd${rb.getAttribute('data-name')}"]`);
if (hd && rb.checked) hd.value = rb.value;
console.log(rb)
console.log(hd.value)
}
< /code>
Ich verwende eine versteckte Eingabe, um den ausgewählten Wert zu speichern. Und Konsole zeigt dies: < /p>
""
""
N
N