1

I'm new to ASP.NET MVC and I'm just trying to call a JavaScript function to record a user's listbox selection. I have the JavaScript function duplicated in THREE PLACES, but it still can't be found. What am I doing wrong?

Here's the code for the view. The function I'm trying to call is JobSelected, in the onselect attribute:

@model IList<Nexient.Net.Orgchart.Data.Models.JobTitle>
@{
 ViewBag.Title = "Delete";
}
<h2>Delete</h2>
@using (Html.BeginForm())
{
 @Html.AntiForgeryToken()
 @Html.ValidationSummary(true)
 <head>
 <title>the title</title>
 <script type="text/javascript">
 function JobSelected() {
 alert("In JavaScript!");
 }
 </script>
 </head>
 <select multiple="multiple" size="10" onselect="JobSelected();" id="JobList">
 @foreach (var jobTitle in Model)
 {
 <option>
 @jobTitle.Description
 </option>
 }
 </select>
 <fieldset>
 <legend>Please select job title(s) to delete.</legend>
 <p>
 <input type="submit" value="Delete"/>
 </p>
 </fieldset>
}
<div>
 @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
 function JobSelected() {
 alert("In JavaScript!");
 }
</script>
@section Scripts {
 @Scripts.Render("~/bundles/jqueryval")
<script type="text/javascript">
 function JobSelected() {
 alert("In JavaScript!");
 }
</script>
}
tereško
58.5k26 gold badges100 silver badges151 bronze badges
asked Jul 8, 2015 at 15:49

1 Answer 1

5

The onselect event is triggered when text is selected (highlighted) in a control. You probably meant to use onchange instead, which is triggered when the value of the control changes (such as by selecting a different option in the select control).

answered Jul 8, 2015 at 15:54

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.