Buy Now
Sign in

Dynamic dropdown problem when double quote (") is present

rotocal , April 20 2020, 22:53
rotocal 48
April 20 2020, 22:53 #392087
Dynamic dropdown field is reading data from a database table (MySql). The field in consideration reads Item descriptions of hardware. When I select items with a " (double quote), like - Screw black 1" - or - Screw black 2-1/2" - or - Screw 2 1/2" (Black) - I can see the result in the selection field, and it is OK see please screenshot below. However, when I try to run an Ajax request to PHP in order to read the database (based on description) and bring back the remaining data for this form, the description can not be read because the quote, and nothing pass to the ajax request to PHP. The other descriptions (without the double quote) work perfectly . How can I solve this issue please.
Even after submission of the form trying to assing the value to $description = $this->data['Description'] ; doesn't work when a double quote is present. Tried also with mysql REPLACE (Description, '"', '\"') when reading the dynamic data. Thank you
Part of the event and ajax call ... (event can be simple javascript as well addEvent Listener)
var selBox = $('#descripcionpop').find(":selected").html();
console.log('Selected text value is ',selBox);
selBox = $('#descripcionpop').find(":selected").val();
console.log('Selected actual value is ',selBox);

alert("In event.....!! - " + selBox);

url : '/includes/descrip-popup.php',
type: "POST",
data : {descripcion : selBox},
success: function(response,status,xhr)
{ .................
admin 33
April 22 2020, 15:54 #392123
I'm not sure but the double quotes are in the options values and text or only text ? if they are in the values then please check the page source, do they break the options code ?
rotocal 48
April 23 2020, 13:44 #392141
Yes they are in the values and brake the code producing a undefine value to be pass to the ajax request. The thing is ... that people creating new items could write this 2-1/4" instead of 2-1/4 inch all the time, .....something I can not control. Thanks
admin 33
April 23 2020, 14:00 #392145
Did you check the page source ? does it break the value attribute ? if yes then you will need to convert quote to special chaarcters using PHP first!