I am not able to select option whose value contain special characters in datalist I’m able to select only Option which do not contain special characters.
<label class="form-label">Seller</label>
<?php $seller = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM party_details Where id= '".$submit['seller_id']."'")); ?>
<input id="seller" list="get_seller" type="text" class="form-control" value="<?php echo $seller['cname'].'-'.$seller['city']; ?>" name="seller" readonly>
<input type="text" id="seller_id" name="seller_id" value="<?php echo $submit['seller_id']; ?>" class="form-control" />
<datalist id="get_seller">
<?php
$seller = mysqli_query($conn,"SELECT * FROM party_details ");
while($sellers = mysqli_fetch_array($seller)) { ?>
<option value="<?php echo $sellers['cname'] ; ?>"><?php echo $sellers['cname'].'-'.$sellers['city'] ; ?></option>
<?php } ?>
</datalist>
$(document).ready(function() {
document.getElementById('seller').onchange = function() {
var input = document.getElementById('seller').value;
$.ajax({
type: "POST",
url: "php/get_party_city.php",
data: "id=" + input,
success: function(data) {
//$('#gstR'+rowIdx).val(data['gst']);
$("#seller_id").val(data['selected_id']);
$("#seller").val(data['with_brand']);
}
});
}
});
Page to get id:
<?php
include('connection.php');
$name = mysqli_real_escape_string($conn,$_POST['id']);
$sql = mysqli_fetch_array(mysqli_query($conn,"SELECT * FROM party_details WHERE cname = '$name'"));
$option = $sql['cname']."-".$sql['city'];
$set_id = $sql['id'];
$opt = mysqli_real_escape_string($conn, $option);
header('Content-Type: application/json');
echo json_encode(array('selected_id' => $set_id,'with_brand' => $opt));
?>




