`createIrecButton.addEventListener("click", function (event) {
event.preventDefault(); // prevent the form from submitting
// get the form by its id
const myForm = document.getElementById("myForm");
// get the input elements from the form
const inputs = myForm.querySelectorAll("input");
// create an empty object to store the input values
const data = {};
// loop through the input elements
inputs.forEach(function (input) {
// get the input name and value
const name = input.name;
let value = "";
// check if input is a radio button
if (input.type === "radio") {
// check if input is disabled or unchecked
if (input.disabled || !input.checked) {
value = "";
} else {
value = input.value;
}
} else if (input.tagName === "SELECT") {
// check if input is disabled or no option selected
if (input.disabled || input.selectedIndex === -1) {
value = "";
} else {
value = input.options[input.selectedIndex].value;
}
} else if (input.type === "checkbox") {
// checkbox input
if (input.disabled || !input.checked) {
value = "";
} else {
value = input.value;
}
} else {
// input is not a radio button, checkbox, or select box
value = input.value;
}
// add the name-value pair to the data object
data[name] = value;
});
radio buttons are initially disabled but are enabled later. even when a radio button is checked i’m still just returning the value of “”. Sorry I’m very new. Thanks in advance
here's an example of one a couple of the radio buttons:
<input
id="phone1typeMobile"
type="radio"
name="phoneType1"
value="Cell phone - "
style="margin-right: 0"
disabled
/><label for="phone1typeMobile">M</label>
<input
id="phone1typeLandline"
type="radio"
name="phoneType1"
value="Landline - "
style="margin-right: 0"`your text`
disabled
/><label for="phone1typeLandline">L</label>
Looking to get the values pushed into my object instead of just returning “”
can’t seem to figure out why it doesn’t record the value. if you need more information please let me know. this is my first coding project.