I am using Laravel and I have an update modal. My data is not set on the modal because one of the data contain quotation mark like in the picture below.
My button’s code is like this:
<a type="button" data-toggle="modal" data-target="#cartitem_update_modal" class="dropdown-toggle btn btn-warning btn-circle" onclick="cartitem_update_modal('{{ $getdata->EQC_ID }}' , '{{ $getdata->EQC_ITEM_ID }}' , '{{ $getdata->EQC_ITEM_NAME }}' , '{{ $getdata->EQC_ITEM_QUANTITY }}' , '{{ $getdata->EQC_ITEM_UNIT }}' , '{{ $getdata->EQC_ITEM_REMARK }}')"> <span class="fa fa-edit" aria-hidden="true"></span> </a>
and my javascript code is like this:
function cartitem_update_modal(EQC_ID, EQC_ITEM_ID, EQC_ITEM_NAME, EQC_ITEM_QUANTITY, EQC_ITEM_UNIT, EQC_ITEM_REMARK) { $('#cart_item_id_update').val(EQC_ID); $('#cart_item_update').val(EQC_ITEM_NAME); $('#cart_item_reserved_quantity_update').val(EQC_ITEM_QUANTITY); $('#cart_item_reserved_unit_update').val(EQC_ITEM_UNIT); $('#cart_item_remark_update').val(EQC_ITEM_REMARK); }
And my problem is the Item Name not appear on my textbox <input type="text" class="form-control" id="cart_item_update" readonly>
and it is because the data has quotation mark. I tried select the data which not contain quotation mark, and it’s worked well, the data showed up in the text box.
Advertisement
Answer
Since you know that you will be using it inside a javascript call, just replace the '
by '
or replace it with (space) or nothing
<a type="button" data-toggle="modal" data-target="#cartitem_update_modal" class="dropdown-toggle btn btn-warning btn-circle" onclick="cartitem_update_modal('{{ $getdata->EQC_ID }}' , '{{ $getdata->EQC_ITEM_ID }}' , '{{ str_replace("'", "'", $getdata->EQC_ITEM_NAME) }}' , '{{ $getdata->EQC_ITEM_QUANTITY }}' , '{{ $getdata->EQC_ITEM_UNIT }}' , '{{ str_replace("'", "'", $getdata->EQC_ITEM_REMARK) }}')"> <span class="fa fa-edit" aria-hidden="true"></span> </a>