facebook

Multiple nested IF statements

💡
Our Forums Have Moved

For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub

  1. MobiOne Archive
  2.  > 
  3. Getting Help – General
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #343356 Reply

    Robert Gardner
    Participant

    I’m having some difficulty trying to construct a series of nested IF statements in Javascript. I know what I would do in other languages (old school stuff like Cobol, Assembler).

    Here’s what I need to do… Consider.. The checkbox will either be set or not. The other comparison values will either be 1, 2 or 3. Calculation is different depending upon the combination of the checkbox and other value (1 2 or 3).

    If (variable_name == “1”) && (checkbox value is SET)
    then totalcharges = non-regularRate1 * qty
    If (variable name ==”1″ && (checkbox value is NOT SET)
    the totalcharges = regularRate1 * qty.

    If (variable_name == “2”) && (checkbox value is SET)
    then totalcharges = non-regularRate2 * qty
    If (variable name ==”2″ && (checkbox value is NOT SET)
    the totalcharges = regularRate2 * qty.

    If (variable_name == “3”) && (checkbox value is SET)
    then totalcharges = non-regularRate2 * qty
    If (variable name ==”3″ && (checkbox value is NOT SET)
    the totalcharges = regularRate3 * qty.

    Can’t seem to wrap my head around it? One issue I’m having is placing braces and ; properly. Can anyone share a solution?

    As you might imaging I’m fairly new to JS..

    Thanks,

    #343358

    Brandon
    Member

    Try something like this:

    if($(‘#form1-toggle1 input’).is(‘:checked’) == true && myVariable == ‘1’)
    {
    //do this
    }

    References
    http://www.genuitec.com/mobile/docs/widgetReference/widgetReference.html#list_properties

    http://www.w3schools.com/js/js_if_else.asp

    #343360

    Robert Gardner
    Participant

    doesn’t this statement state if BOTH are true?

    if($(‘#form1-toggle1 input’).is(‘:checked’) == true && myVariable == ‘1’)

    If so, I need something that says if the checkbox is not TRUE

    also… I posted in another post questioning why when I save the value of the checkbox to a variable it always has the value of ON regardless of the box being checked or not… Do you know what’s happening there?

    Thank you for your prompt response..

    #343361

    Robert Gardner
    Participant

    I tried the == true and also != true implementations by themselves (not using the compound condition) to see if either would work… They didn’t

    #343362

    Brandon
    Member

    If its unchecked it will be false instead of true.
    You can also make sure you are getting a result by setting the value in a n alert:

    alert($(‘#form1-toggle1 input’).is(‘:checked’));

    This will help make sure you get the form name and widget name correct.
    If it is not returning true or false something is wrong.

    #343364

    Robert Gardner
    Participant

    Well,… the devil is always in the details…. Upon closer look at your widget construction I noticed the “>” was omitted. What is the purpose of the greater than sign? Perhaps I overlooked but it but I don’t see it’s purpose documented anywhere?

    How does this

    $('#form1-toggle1 input').is(':checked')

    …differ from

    $('#form1-toggle1 > input').is(':checked')

    It’s all a learning experience…

    #343432

    Hi aviator21114,

    I followed up with you on this other checkbox thread:
    http://www.genuitec.com/support-genuitec/viewtopic.php?p=21219#p21219

    Do you still have problems with checkboxes snippets?

Viewing 7 posts - 1 through 7 (of 7 total)
Reply To: Multiple nested IF statements

You must be logged in to post in the forum log in