0

i would like to create a Json object using an AND condition (i dont know if its possible). I put the unfinished code that i've by the moment.

var parameters = {
                Title : "hello",
                Text : "world",
                Question : //if two checkboxes are checked then true else false.
}

About the two checkboxes checked i was thinking to use this:

$('.checkbox1').is(':checked') && $('.checkbox2').is(':checked')

What i would like to avoid is to put an if like

//if checkboxes are checked
//{
//create the json object of type 1
//}
//else
//{
//create the json object of type 2
//}

Is this possible?

1
  • 1
    Have you just tried it? Btw. this is not a JSON object. It is a normal JavaScript object. Commented May 6, 2011 at 10:07

1 Answer 1

1

Yes, a boolean would be ok:

var parameters = {
            Title : "hello",
            Text : "world",
            Question : $('.checkbox1').is(':checked') && $('.checkbox2').is(':checked')
}

This will create a regular JavaScript object which you can manipulate like any other object, e.g.,

parameters.Question = <newTrueOrFalseToSet>;

Or even:

parameters["Question"] = <newTrueOrFalseToSet>;

According to the JSON definition, the resulting JSON should look like:

{
    "Title": "hello",
    "Text": "world",
    "Question": true
}
Sign up to request clarification or add additional context in comments.

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.