Can someone help me get the text of my option tag because i always get blank when i do.
here is the html/php
<div class="form-group">
<label for="sel1" id = "type_set">Webhook Type:</label>
<select name="type" id = "selecting">
<option value="" selected disabled hidden >Choose Tagging</option>
<?php
$disp = PDODatabase::Instance()->QueryAll("SELECT * FROM social_media" );
foreach($disp as $data){
if($data['_DELETED'] != 1){
echo "<option data-med='".$data['SOCIAL_NAME']."' id = 'soc' value='".$data['ID']."'>".$data['SOCIAL_NAME']."</option>";
}
}
?>
</select>
</div>
here is the script:
jQuery(document).on('click','#soc', function(e){
e.preventDefault();
var med = $('#selecting:selected').text();
alert(med);
// var tod = ""+year+""+month+""+dat+""+ran+""+med+"";
// document.getElementById("wname_set").value = tod;
});
thank you T_T
#selecting
is the ID of the <select>
, you need to select the selected option.
var med = $('#selecting option:selected').text();
Please try:
$('#selecting option:selected').text();
If you want to get the value then go with this one :
var med = $("#selecting option:selected").val();
console$('#selecting option:selected').text())