Getting selected values without redirecting to another page using Jquery or javascript -
hi trying selected value dropdown using jquery. when click on option redirecting page , because of not able see output on console. can me out code?
this tried
if(typeof jquery == "undefined"){ $(document).ready(function() { $("#uniqname_7_0defaultselect").change(function() { var selectedtext = $(this).find(":selected").text(); console.log(selectedtext); }); }); }
try use preventdefault()
prevent default action :
$(document).ready(function() { $("#uniqname_7_0defaultselect").change(function(e) { e.preventdefault(); var selectedtext = $('option:selected', this).text(); console.log(selectedtext); }); });
hope helps.
$(document).ready(function() { $("#uniqname_7_0defaultselect").change(function(e) { e.preventdefault(); var selectedtext = $('option:selected', this).text(); console.log(selectedtext); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select id="uniqname_7_0defaultselect"> <option value="valeur1">option 1</option> <option value="valeur2">option 2</option> <option value="valeur3">option 3</option> </select>
Comments
Post a Comment