You are viewing limited content. For full access, please sign in.

Question

Question

Set value in drop down list with Javascript

asked on March 19, 2019

Hello!

I've got a super simple question. I was to set the value of one drop down list with the contents of another one when it is changed. I've tried this script, but I can't seem to detect the change/blur/click whatever.

Here's what I've got:

$(document).ready(function(){
  alert("running"); // Test to see if Javascript is running, and it is
  $('.presenter input').change(function () { //also tried $('#q3 input') 
    	alert("still running"); // Script doesn't run this
        $('.assign input').val($(this).val());
  });

});

Thanks!

0 0

Answer

SELECTED ANSWER
replied on March 19, 2019

If it is a drop down use select...

$(document).ready(function(){
  alert("running"); // Test to see if Javascript is running, and it is
  $('.presenter select').change(function () { //also tried $('#q3 input') 
    	alert("still running"); // Script doesn't run this
        $('.assign select').val($(this).val());
  });
});
2 0
replied on March 19, 2019 Show version history

Hey thanks! You can probably tell Javascript isn't my strong suit.

Now it does execute the alert("still running"); but doesn't actually modify the .assign drop down. Any helpful tips on what could be going wrong there?

EDIT: Completely slipped my mind to mention that the .presenter drop down is just the list by itself, but the .assign drop down has a separate value list associated with it as well, but we're trying to match up the label list on both (they are the same for both drop downs).

EDIT2: That's exactly the problem. When referencing the select value from the first drop down, I get the label, but for the second drop down, I get the value of the label instead, which makes perfect sense. Is there any way I can get the label instead?

EDIT3: Just decided to make both lists value lists instead. That worked like a charm. Thanks again!

1 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.