Mehar44 Mehar44 - 18 days ago 5
jQuery Question

jQuery : How to replace an element with a new and only show the new one?

In the following code I am showing order_status in admin panel of opencart when admin edits an order. The order status is showing perfectly fine.

<?php if ($info_data['order_status']) { ?>
<td><?php echo $info_data['text_order_status'];?</td>
<td id="order-status"><?php echo $info_data['order_status']; ?></td>
<?php } ?>

But when admin update the order_status by selecting from a drop down list it shows the updated order_status with the old order_status. I need to only show the updated order_status , How can I replace the old status with the updated order_status?

if (json['success']) {
$('#history').load('index.php?route=sale/order/history&token=<?php echo $token; ?>&order_id=<?php echo $order_id; ?>&shipping_code=<?php echo $shipping_code; ?>');

$('#history').before('<div class="alert alert-success"><i class="fa fa-check-circle"></i> ' + json['success'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');



$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());

I guess this line should do the replacement , but it is not working properly , what should I change? Please Help !

$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());

Code for select box

<div class="form-group">
<label class="col-sm-2 control-label"
for="input-order-status"><?php echo $info_data['entry_order_status']; ?></label>
<div class="col-sm-10">
<select name="order_status_id" id="input-order-status" class="form-control">
<?php foreach ($info_data['order_statuses'] as $order_statuses) { ?>
<?php if ($order_statuses['order_status_id'] == $info_data['order_status_id']) { ?>
<option value="<?php echo $order_statuses['order_status_id']; ?>"
selected="selected"><?php echo $order_statuses['name']; ?></option>
<?php } else { ?>
value="<?php echo $order_statuses['order_status_id']; ?>"><?php echo $order_statuses['name']; ?></option>
<?php } ?>
<?php } ?>


Try this:


$('#order-status').html($('select[name=\'order_status_id\'] option:selected').text());


$('#order-status').html($('#input-order-status option:selected').text());

if you want to call your selectbox with name then change it


$('#order-status').html($('select[name="order_status_id"] option:selected').text());