0

I've got three dropdown menu's which are dynamically filled from the database each time I select an option in the previous dropdown menu.

Now I want to access the values in these dropdown menu's, so that I can build a SQL-query somewhere later.

I've used the following code to access the HTML elements:

$( window ).load(function(){
    var e = document.getElementById("slctTable");
    var slctTableValue = e.value;
    console.log(slctTableValue);
});

This code only works the first time the page loads, so when I mess around with the dropdown menu's, nothing changes.

What I want now, is that each time I select a value in the dropdown menu, it updates the slctTableValue variable.

4
  • does the answers solved your problem? Commented May 17, 2016 at 11:01
  • yeah they do, thank you Commented May 17, 2016 at 11:38
  • You need to relax and give people some time to work, you'll get your recognition Commented May 17, 2016 at 11:41
  • What do you meant by that? Commented May 17, 2016 at 11:43

2 Answers 2

2

Bind change event to the drop-down with jquery, then this event will fire whenever there is a change happened on the selected value.

$("#slctTable").change(function() {
  var slctTableValue = $(this).val();
  console.log(slctTableValue);
});
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I've tried it before but couldn't get it to work for some reason. Now I got what I need.
1

You can detect change event like this and update value:

    document.getElementById('slctTable').addEventListener('change',function(){
       var e = document.getElementById("slctTable");
       var slctTableValue = e.value;
       console.log(slctTableValue);
    });

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.