Abdul Waheed Abdul Waheed - 5 months ago 34
Ajax Question

Can we get the slected options Text of select menu using jquery "Dynamic option values"

I want to show the drop value text but the thing is these values are dynamic,what is the correct way to approach,and right now only id values are coming now.

<div class="form-group">
<select class="wp-form-control" id="joblocation" name="joblocation">
<option value="0">Select Job Location</option>
<?php $City = $conn->query("SELECT * FROM tbl_cities ORDER BY city_pid ASC");
while ($Cityresult = $City->fetch_assoc()) {?>
<option value="<?php echo $Cityresult['city_pid']; ?>"> <?php echo $Cityresult['city_name']; ?> </option>
<?php } ?>

And Script:

var joblocation = $('#joblocation').find(":selected").text();

And i want to show the dropdown selected text here:

<span id="joblocation1"> </span>


Try the following code :

//This is for debugging and will show you the selected option object in console
console.info($("#joblocation option:selected") );

$("#joblocation1").html($("#joblocation option:selected").text() );