I am facing an issue with the visibility of my buttons. Currently, I have 3 buttons whose visibility is set to hidden. Upon clicking a specific button, an Ajax call is triggered where I check if the table rows are greater than 0 in the success callback:
$('#addRefBtn').on('click', function(e){
e.preventDefault();
var get_input = $('#qr_ref').val();
var get_po = $('#get_po').val();
$.ajax({
type: 'POST',
url: 'validate_qr.php',
data: {
qr_code: get_input,
po_ID: get_po
},
success: function(result)
{
var rowCount = $('#productSalesTable tbody tr.ps').length;
if(rowCount > 0)
{
$('#promoModal, #removeModal, #confirmModal').css('visibility', 'visible');
}
else
{
$('#promoModal, #removeModal, #confirmModal').css('visibility', 'hidden');
}
}
});
});
The location.reload()
was commented out for checking purposes and it confirmed that the button's CSS changes when the table row count is greater than zero.
However, upon page reload, the buttons revert back to their original hidden state which is causing concern.
This is the relevant HTML code:
<div id='promoModal' style='visibility:hidden;'>
<button type="button" class='btn btn-block btn-primary btn-flat' id="promo_modal" data-poid="<?php echo $_GET['po_ID'];?>">
Add Promo
</button>
</div>
<div id='removeModal' style='visibility:hidden;'>
<input type="button" class='btn btn-block btn-warning btn-flat' id="remove_modal" value="Remove Item">
</div>
<div id='confirmModal' style='visibility:hidden;'>
<button type="button" class='btn btn-block btn-success btn-flat' id="confirm_modal" data-id="<?php echo $_GET['po_ID'];?>">
Confirm Transaction
</button>
</div>
Despite knowing that the code is functioning correctly, the button styles do not change as expected even when the table length is greater than zero.
If anyone has suggestions or feedback on this matter, it would be greatly appreciated!
Thank you for your time.