You probably need a hidden input outside of the loop. Then set the value of the hidden field using javascript. Something like:
<?php
$wa_startindex = 0;
while(!$Profile_RS->atEnd()) {
$wa_startindex = $Profile_RS->Index;
?>
<div class="col-lg-6">
<div class="feature-item">
<h3><a href="#" name="md" class="text-decoration-none" onClick="document.getElementById('md').value='<?php echo($Profile_RS->getColumnVal("bg_id")); ?>';document.getElementById('customerID').value='<?php echo($Profile_RS->getColumnVal("customer_id")); ?>';framework_load_plugin_url('plugins/plugins/details.php',document.getElementById('Checkout_form'),'callme','../','');return document.MM_returnValue"><?php echo($Profile_RS->getColumnVal("firstname")); ?> <?php echo($Profile_RS->getColumnVal("lastname")); ?></a></h3>
</div>
</div>
<?php
$Profile_RS->moveNext();
}
$Profile_RS->moveFirst(); //return RS to first record
unset($wa_startindex);
unset($wa_repeatcount);
?>
<input type="hidden" name="md" id="md" value="">
<input type="hidden" name="customerID" id="customerID" value="">