Quote:
<label id="locationdepart" class="control-label"> Stockage de depart </label>
<select id="locationdepart" class="form-control" asp-items="ViewBag.fromlocation"> </select>
<span id="locationdepart" class="text-danger"> </span>
You're setting the same
id
on the label, the form element, and the validation message. IDs in an HTML document must be unique.
Since you're using ASP.NET Core, you can use the tag helpers to generate the correct IDs:
<label asp-for="locationdepart" class="control-label"> Stockage de depart </label>
<select id="locationdepart" asp-for="locationdepart" class="form-control" asp-items="ViewBag.fromlocation"> </select>
<span asp-validation-for="locationdepart" class="text-danger"> </span>
If you view the page source in your browser, the rendered HTML should look something like:
<label for="locationdepart" class="control-label"> Stockage de depart </label>
<select id="locationdepart" name="locationdepart" class="form-control"">
<option value="...">...</option>
...
</select>
<span class="text-danger field-validation-valid" data-valmsg-for="locationdepart"></span>
Your script should then start working:
function onAddClick() {
var transfertDep = document.getElementById("#locationdepart").value;
console.log(transfertDep);
...
}