Mthe beseti Mthe beseti - 4 months ago 15
jQuery Question

Billing same as Shipping Address / Remove Billing Options

I'm new to jquery. I'm working on a ecommerce website. there is a billing address involved. the issue that there is a physical address that the user has to provide for the billing address. but if the billing address is the same as shipping address, then the link to edit the shipping address should be hidden.

So i think jQuery can do the trick of removing a link. I would like to know how can I approach this matter using jQuery


A pretty much generalized example

$('#ship, #bill').change(function() {
  var bill_val = $('#bill').val(); // save the current values in vars
  var ship_val = $('#ship').val();
  console.log(bill_val + ' = ' + ship_val) // debug purposes
  if (bill_val === ship_val && bill_val.trim().length && ship_val.trim().length) {
  // the if above checks to see if they are the same and if they aren't just spaces
    $('.edit').fadeOut(); //or .hide() for no fade
  } else {
    $('.edit').fadeIn(); //or .show() for no fade
<script src=""></script>
<input type='text' id='ship' />
<input type='text' id='bill' />
<a href='javascript:;' class='edit'>Edit</a>

This example can be adjusted to accept only numbers, trim spaces more and other checks as needed.