facebook

"else if" assistance please

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

    mach_stik
    Member

    Hi,

    Some help please.

    I have a text field that is already calculating, from this text field i want another text field to calculate on a button command click with an else if function.

    So…..
    on click
    if textfield < ’10’;
    newtextfield = “under range”;
    else if text field == “10”;
    newtextfield = “in range”;
    else newtextfield = “over range”;

    If anyone can help it would be greatly appreciated.

    thank you
    Adam

    #336242 Reply

    Brandon
    Member

    This is off the top of my head and not knowing your form name but:

    
    if($('#m1-yourform-textField1')val() < 10)
    {
    
    $('#m1-yourform-newtextField1')val('Under Range');
    
    }else if ($('#m1-yourform-textField1')val() == 10)
    {
    
    $('#m1-yourform-newtextField1')val('In Range');
    
    }else
    
    {
    
    $('#m1-yourform-newtextField1')val('Over Range');
    
    }
    
    
    
    #336318 Reply

    JustJohn
    Member

    Another way to approach this is with a Switch statement.
    The following will work as a test. Just replace the necessary variables and fields.

    function OnClick()
    {
    var amount = 10; // Represents your textfield
    var newtextfield = “”;

    switch(true)
    {
    case (amount < 10):
    newtextfield = “under range”;
    break;
    case (amount == 10):
    newtextfield = “in range”;
    break;
    case (amount > 10):
    newtextfield = “over range”;
    }

    alert(newtextfield);
    }

    #337004 Reply

    mach_stik
    Member

    Thanks guys, great help, will try both and see what happens

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: "else if" assistance please

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