views:

61

answers:

5

This is probably pretty simple, but I can't figure out how to do it: I have this code:

$.post("/admin/contract", {
                          'mark_paid' : true,
                          'id' : id
        },

In pseudo code, how can I do this:

$.post("/admin/contract", {
                          'mark_paid' : true,
                          'id' : id,
                          if(is_set(dont_email)) {print 'dont_email' : true}
        },
+2  A: 

I'll give it a try :

$.post("/admin/contract", {
                          'mark_paid' : true,
                          'id' : id,
                          'dont_email' : is_set(dont_email) ? true : undefined
        },
Thomas Wanner
+1  A: 
var details = {
    'mark_paid' : true,
    'id' : id,
}

if(is_set(dont_email)) {
    details.dont_email = true;
}

$.post("/admin/contract", details);

untested...

Ross
+7  A: 

How I'd do it.

$.post("/admin/contract", {
  'mark_paid' : true,
  'id' : id,
  'dont_email' : ( 'undefined' != typeof dont_email )
},
Peter Bailey
Is what I was going to write. The cleanest solution.
Andy E
A: 

Try this:

$.post("/admin/contract", {
                 'mark_paid' : true,
                 'id' : id,
                 'dont_email': (is_set(dont_email))?true:false
            },
antyrat
A: 

I'm not sure I understand your question correctly. Is dont_email a variable? Are you checking the existence of dont_email?

var myDontEmail = (typeof(dont_email) != "undefined");

$.post("/admin/contract", {
             'mark_paid' : true,
             'id' : id,
             'dont_email': myDontEmail
        },
ghoppe