3

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 } ?>
    </select>
</div> 

And Script:

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

And i want to show the dropdown selected text here:

<span id="joblocation1"> </span>
Mr world wide
  • 4,696
  • 7
  • 43
  • 97

2 Answers2

3

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() );
shivgre
  • 1,163
  • 2
  • 13
  • 29
1

you could try this

 var optionText = $("#joblocation option:selected").text() //gets you the text from the selected option


And then add the variable to the span like so:

$("#joblocation1").text(optionText);
TheWandererr
  • 514
  • 1
  • 8
  • 34
  • Please edit with more information. Code-only and "try this" answers are discouraged, because they contain no searchable content, and don't explain why someone should "try this". – abarisone Sep 27 '16 at 14:23