javascript - Change the value of label with change in drop-down value using JQuery -


i trying change value of label change in drop-down value using jquery not working. please me fix this.

<select id="myselect">     <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option>     <option value="5">5</option> </select> <br/> <label id="label"></label> <br/> 
$("label").val("150.000.000"); $(("#myselect").val()).on('change', function() {     if ($("#myselect").val() == '1') {         $("#label").val("150.000.000");     } else  {         $("#label").val("350.000.000");     } }); 

your selector attached change event incorrect, need provide id of element string, not value of element itself. also, label elements don't have value need use text() change them, , can use this within changehandler refer select element. try this:

$("label").text("150.000.000");  $("#myselect").on('change', function() {    if ($(this).val() == '1') {      $("#label").text("150.000.000");    } else {      $("#label").text("350.000.000");    }  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <select id="myselect">    <option value="1">1</option>    <option value="2">2</option>    <option value="3">3</option>    <option value="4">4</option>    <option value="5">5</option>  </select>    <br/>  <label id="label"></label>  <br/>

you can shorten js code this:

$("label").text("150.000.000"); $("#myselect").on('change', function() {     $("#label").text(function() {         return $(this).val() == '1' ? "150.000.000" : "350.000.000";     }) }); 

Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -