0

I'm creating a web form using the bootstrap wizard.

Here I'm stuck within a few operations.

As a first step, I have added a drop-down menu and there in the selected event, I'm taking the selected value from the javascript. That's working fine.

So in the next section, there is another combo box and the selection change event I also want to get the selected value of that combo box and the previously selected combo box value.

So I did this method but it does not return the selected value.

Can you help me with this?. Still, I'm not good with javascript

This is the first combo box.

 <div class="form-row center">
   <div class="form-holder"> @Html.DropDownListFor(model => model.Language, new SelectList(new[] { "English", "සිංහල", "தமிழ்" }),"Please Select the Language", new { @class = "form-control js-dropdown",Id ="DropLanguage" }) </div>
 </div>

This is the second Combo box

<div class="form-holder w-100">
  <div class="col-md-12"> @Html.DropDownList("ServiceTypeId", null,language == "Secondary" ? "For which service you came for?" : language == "Primary" ? "ඔබ පැමිණියේ කුමන සේවාව සඳහාද?" : language == "Third" ? "நீங்கள் எந்த சேவைக்காக வந்தீர்கள்" : "", htmlAttributes: new { @class = "form-control", Id = "ServiceType" }) <i class="zmdi zmdi-quote"></i> @Html.ValidationMessageFor(model => model.ServiceTypeId, "", new { @class = "text-danger" }) </div>
</div>

This is the javascript

< script type = "text/javascript" >
  $(document).ready(function () {
    $("#DropLanguage").on("change", function () {
      // This is the jQuery way of finding selected option's text
      var myVar = $(this).find("option:selected").text();

      // Post the value to your server. You should do some error handling here
      $.ajax({
        url: '/MainDetails/SetSession',
        type: 'POST',
        dataType: 'json',
        cache: false,
        async: false,
        data: {
          myVariable: myVar
        },
        success: function (data) {
          if (data.Success == true) {

            $("#mydiv").load(window.location.href + " #mydiv");
          }
        }
      });

    });

    $("#ServiceType").on("change", function () {

      var ServiceId = document.getElementById("ServiceType");
      var Language = document.getElementById("DropLanguage");

      alert(ServiceId);
      alert(Language);

    });
  });

<
/script>

Im not getting value on this section $("#ServiceType").on("change", function () {

T.kowshik Yedida
  • 195
  • 1
  • 2
  • 13
Dev Beginner
  • 589
  • 1
  • 11
  • Use developer tools and run your js statement in the console. Most probable reason is the id might be different from what is expected. – T.kowshik Yedida Apr 18 '22 at 03:56
  • Hi, @T.kowshikYedida I have used the developer tool console, But on the change, it doesn't hit anything on it. – Dev Beginner Apr 18 '22 at 04:04
  • Did you check the id of element? Is it correct? – T.kowshik Yedida Apr 18 '22 at 04:11
  • @T.kowshikYedida Yes. ``ServiceType`` is the Id. This is the dropdown ``@Html.DropDownList("ServiceTypeId", null,language == "Secondary" ? "For which service you came for?" : language == "Primary" ? "ඔබ පැමිණියේ කුමන සේවාව සඳහාද?" : language == "Third" ? "நீங்கள் எந்த சேவைக்காக வந்தீர்கள்" : "", htmlAttributes: new { @class = "form-control", Id = "ServiceType" })`` – Dev Beginner Apr 18 '22 at 04:17
  • Ok. See this answer https://stackoverflow.com/a/25056654/5798300 – T.kowshik Yedida Apr 18 '22 at 04:27
  • @T.kowshikYedida Thanks a lot. I got the answer from your link. How do I mark your comment as answer? – Dev Beginner Apr 18 '22 at 04:34
  • You can close this question as not accepting answers. That should be fine – T.kowshik Yedida Apr 18 '22 at 04:52

0 Answers0