JavaScript select optionlist jquery function select option list jquery,get select option list jquery,jquery

<select id="RB_0_field_select_0">
    <option value="">Select a Field</option> 
    <option value="Audit">Audit</option>
    <option value="Author">Author</option> 
    <option value="Barcode">Barcode</option>
    <option value="Category">Category</option>
    <option value="DocType">Content Type</option>
</select>

<script type="javascript">
    $('select[id="RB_0_field_select_0"]').change(function(){
        alert("hello");
        alert($(this).val());
        alert($( "#RB_0_field_select_0 option:selected" ).text());
    });
</script>

I want to print the value selected in option list but its not working. How to do this?

Answer:1

Your code is working, you just need to include jquery on top:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>   

Here is a demo, I did not change anything in your code, i just added jquery

$('select[id="RB_0_field_select_0"]').change(function() {
  alert("hello");
  alert($(this).val());
  alert($("#RB_0_field_select_0 option:selected").text());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<select id="RB_0_field_select_0">
  <option value="">Select a Field</option>
  <option value="Audit">Audit</option>
  <option value="Author">Author</option>
  <option value="Barcode">Barcode</option>
  <option value="Category">Category</option>
  <option value="DocType">Content Type</option>
</select>
Answer:2

If it doesn't alert even "hello" it means that you are binding event before DOM is loaded - so you don't attach event handler at all to anything. Try to do it on DOMContentLoaded event:

$(function() {
    $("#RB_0_field_select_0").change(function () {
        $(this).val();
    });
});
Answer:3

I'm using this piece of code: function setShadowDOM(i, css){ [].forEach.call(document.getElementsByTagName(i), function(hostVal) { var _root = hostVal.createShadowRoot(); ...

I'm using this piece of code: function setShadowDOM(i, css){ [].forEach.call(document.getElementsByTagName(i), function(hostVal) { var _root = hostVal.createShadowRoot(); ...

I want to have a complex dom node have the "open link in new window" context menu option, like you have with any standard <a> tag link. But I don't want that dom node to open up that link when ...

I want to have a complex dom node have the "open link in new window" context menu option, like you have with any standard <a> tag link. But I don't want that dom node to open up that link when ...

I am developing my first app using Vuejs + Laravel and I am facing a problem that I couldn't solve until now! I have an array of object and I need to edit a single of then without delete and add a ...

I am developing my first app using Vuejs + Laravel and I am facing a problem that I couldn't solve until now! I have an array of object and I need to edit a single of then without delete and add a ...

  1. edit object array javascript
  2. edit array object autocad
  3. edit object in array
  4. edit object in array react
  5. edit object in array js
  6. edit object inside array
  7. edit object in array java
  8. edit object in array angularjs
  9. edit object in array angular
  10. unity editor object array
  11. lodash edit object in array
  12. typescript edit object in array
  13. redux edit object in array
  14. mongoose edit object in array
  15. es6 edit object in array
  16. vuex edit object in array
  17. vue edit object in array
  18. mongodb edit object in array
  19. powershell edit object in array
  20. jquery edit object in array

I created two inputs with the ids name and age, and I've been trying to check if data was inserted in them by using javascript's oninput, it worked for age but not for name, what am I doing wrong? ...

I created two inputs with the ids name and age, and I've been trying to check if data was inserted in them by using javascript's oninput, it worked for age but not for name, what am I doing wrong? ...

  1. canvas
  2. canada
  3. cancelled
  4. canceled vs cancelled
  5. cancun
  6. canada goose
  7. cane corso
  8. canes
  9. canadian prime minister
  10. cancun flights
  11. canker sore
  12. candy
  13. cancer
  14. canon
  15. canvas prints
  16. cancer sign
  17. candace owens
  18. canada news
  19. candytopia
  20. canlis