How to populate an input text field attribute

How to populate an input text field attribute

We have a form that includes the following checkbox:

  1. <input type="checkbox" name="status" id="fee" data-subscription="">

I'm trying to write a script that inserts a value into data-subscription. Here's what I have so far, but it's not populating the data-subscription value. 

  1.     if (globally == true) {
  2.         $('input[name="status"]').attr("data-subscription","false")
  3.     } else {
  4.         $('input[name="status"]').attr("data-subscription","true")
  5.     }