0
That is the scenario:
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="">
<form>
<input type="text">
<button type="submit" name="Submit" onclick="addName">Add</button>
<select class="" name="">
<option value=""> - </option>
</select>
</form>
</div>
<script>
function addName() {
const lista = [{
name: document.querySelector('input').value;
}];
// Select tag
const selectOptions = document.querySelector('.selectOptions').option;
lista.forEach(name => {
selectOptions.add(
new Option(option.name);
)
})
}
</script>
</body>
</html>
I need to take the value inserted in this input, and insert it into an array that will be all the contents of the options of this select. I’m stuck in this exercise, I’ve researched everything, I haven’t found a solution. ;-; I’m a beginner, if anyone can shed a light!
I made some more modifications to the code, but now I get the value of "Undefined". --' Function addName() { Let selectMenu = Document.querySelector('.mySelect'); Let option = Document.createelement('option'); Let inputValue = Document.querySelector('.inNputame'). text; selectMenu.add(option, inputValue); Alert(inputValue); }
– r. duarte