Question: I am trying to get the `id` of an `input field` which has a dynamic id but I get an error unrecognized expression. Below is my code : 

```
  $("#amount_paid' + data[i].patient_visit_statement_id + '").keyup(function() {
       var amount_owed = $('#amount_owed' + data[i].patient_visit_statement_id + '').val();
       var amount_paid = $('#amount_paid' + data[i].patient_visit_statement_id + '').val();
       alert('Amount owed' + amount_owed + 'Amount paid' + amount_paid + '');
       if (amount_owed < amount_paid) {
           alert('Amount to be paid exceeds amount owed');
       }
   });

```

What is the best way to get the value from the id amount\_paid which has dynamic id for each entry ?

Answer: 
Code for getting class instance values:

```
// create class instance
InstViewModel model = new InstViewModel()
{
    Uk = true,
    UkNrs = false,
};

// check all boolean fields are false or null
bool isAllNullOrFalse = (from property in typeof(InstViewModel).GetProperties()
                         let type = property.PropertyType
                         let isBool = type == typeof(bool)
                         where isBool || type == typeof(bool?)
                         let value = property.GetValue(model)
                         select value == null || (isBool && bool.Equals(value, false))).All(e => e);

Console.WriteLine("All values are null or false = {0}", isAllNullOrFalse);

```
According to your question

> 
> Basically, I am interest*ed* in finding out if a simple bool variable is true OR if a Nullable variable is not null.
> 
> 
> 

* to tell if a simple boolVariable is true

```
 if(boolVariable){
      //bool variable, not nullable
 }

```
* to tell if your nullableVariable is not null

```
 if(nullableVariable.HasValue){
     //a nullable variable is not null
 }

```
* to tell if nullable bool variable is true or/and not null, use the `??` operator

```
if(variable??false){
   //then I'm sure that this is not null and has value=true
}

```

So in definitive you can use the following code for both nullable bool and bool variables

```
     if(variables!=null &&variables!=false){/*This may give a warning message but it works*/}

```

or

```
   if(((bool?)variable)??false){
      /*variable is not null and is true*/
    }

```