0

I am having trouble getting the code below to work I am not getting any errors. What I need is when #equipmentList1 Changes it displays a dropdown list corresponding to the selection. Then depending on the selecting of the later dropdown it should just write the value of the dropdown selected to the equipmentList2 DIV. selectedVisibleValue1 contains the ID of the field that appears after the first dropdown is chosen I have tried passing it into the second function to write it using innerHTML but it acts like it is not receiving the variable since nothing happens. Maybe I have an error elsewhere in my code. I am new to jQuery so if someone could take a look and let me know what is wrong that would be awesome.

$(document).ready(function () {
  $('#equipmentList1').bind('change', function () {
    var elements = $('div.equipmentList2').children().hide(); // hide all the elements
    var value = $(this).val();    

    if (value.length) { // if somethings' selected
      elements.filter('.' + value).show(); // show the ones we want
      var selectedVisibleValue1 = $(".equipmentList2 select:visible").attr("id");
    }
  }).trigger('change');
});   

$(document).ready(function () {
  $("#" + selectedVisibleValue1).bind('change', function () {
    var value = $(this).val();  

    if (value.length) {
      var equipment = document.getElementById("equipmentList1").value;
      document.getElementById('equipmentList2').innerHTML = selectedVisibleValue1;
    }
  }).trigger('change');
});
1
  • show us some html. Code you have won't work. selectedVisibleValue1 isn't known until a change occurs in other select. Use class as selector to bind change to second select Commented Jan 29, 2013 at 22:47

1 Answer 1

1

You don't need two $(document).ready(...) functions, only one, put all the code in one of them. I'm not sure that's the cause of the issue but there is a good chance.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.