I have a Package Class where a random ID is given at the beginning and a package type can be chosen afterwards.
//Generate PackageId
let generateID = ()=> {
return Math.random().toString(36).slice(2)
}
// choose type of element to be sent
var e = document.getElementById("selectPackageType");
let chooseType = () => {
var value = e.value;
return value;
}
const randomID = generateID();
console.log(randomID);
e.onchange = chooseType;
const typeOfPackage = chooseType();
if (typeOfPackage == null){
console.log("type of packege is null")
}else{
console.log(typeOfPackage);
}
This is the html form. At this moment, there are only two options.
<form autocomplete="off">
<label for="selectPackageType">Type:</label>
<select id="selectPackageType">
<option value="1">letter</option>
<option value="2" >package</option>
</select>
</form>
It seems, that the values are given correctly. I can click between package and letter.But when the method chooseType has been called the second time, the program stops executing, after the method returned the value. The console is not logging the “typeOfPackage”. Any suggestions would be appreciated.