1

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
  • What is dont_email and how is is_set defined? Commented Mar 15, 2010 at 17:30
  • I think he's using the php function is_set to show what he wants in pseudocode. Commented Mar 15, 2010 at 17:35

5 Answers 5

7

How I'd do it.

$.post("/admin/contract", {
  'mark_paid' : true,
  'id' : id,
  'dont_email' : ( 'undefined' != typeof dont_email )
},
Sign up to request clarification or add additional context in comments.

1 Comment

Is what I was going to write. The cleanest solution.
2

I'll give it a try :

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

Comments

1
var details = {
    'mark_paid' : true,
    'id' : id,
}

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

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

untested...

Comments

0

Try this:

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

Comments

0

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
        },

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.