facebook

Testing checkbox value : SOLVED

💡
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 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #343310 Reply

    Robert Gardner
    Participant

    I have a checkbox widget in my app. I’m having difficulty testing it. Code is pretty simple.

    if (progname == 'Elite' && $('#m1-QQ_PeakTravel > input').is(':checked'))
         {alert('test checkbox true')};

    I know the test for the progname works by itself. Have I constructed the compound conditional correctly? Also what about the format of my test for the checkbox?

    I’ve included the properties for the checkbox widget for review if necessary but I don’t see anything special there.

    See attachment Checkbox widget.PNG

    Thanks,

    Attachments:
    You must be logged in to view attached files.
    #343312

    Robert Gardner
    Participant

    I forgot to indicate that I’m running the latest milestone and running the app on an iPad running iOS7 (7.0.2)

    See attachment Mobi version screen.PNG

    Attachments:
    You must be logged in to view attached files.
    #343330

    Robert Gardner
    Participant

    Help I’m stuck on this one! I’m sure it’s a simple overlook of something… Can someone post a suggestion or resolution?

    Thanks.

    #343334

    Hi aviator21114,

    The code looks to be OK. The problem might be the comparison of the progname var, have you tried omitting it to isolate that the problem is not with the checkbox code?

    if($('#m1-QQ_PeakTravel > input').is(':checked'))
        {alert('test checkbox true')};

    I’ve tried your code and it worked well for me assigning “Elite” value to progname var. Let me know if you need further assistance.

    #343335

    Robert Gardner
    Participant

    I’ve tried the checkbox code by itself and it does not seem to work.. Let me stare at it again for a few minutes and see if something sticks out..

    Nope didn’t work…Copied and pasted what you posted (just to be sure)…. Let me also state that I’m not using the “on change” associated with the checkbox widget. I have a push button that executes the javascript to test the value of the checkbox… is this the issue?

    See attachment checkbox push.PNG

    See attachment Pushbutton prop.PNG

    Attachments:
    You must be logged in to view attached files.
    #343336

    Hi,

    Please take a look at next sample file and use it as a baseline to develop your code. Note that I already set the default value of textfield as “Elite” as your code, so it check if textfield contains this value and checkbox is checked, if yes, fire the alert, if not, it fire an error alert.

    If the problem continues let me know where are you testing your app (Test Center, Web Simulator, Device) If device share model and OS.

    Attachments:
    You must be logged in to view attached files.
    #343338

    Robert Gardner
    Participant

    After seeing how you constructed the widget data format I now quickly see the error….

    $('#m1-[b]DistanceCalc[/b]-QQ_PeakTravel > input').is(':checked')
    <!-- method-1 -->
    $('#form1-checkbox1 > input').is(':checked')

    I did not include the filename (form name) in the code construct. I was confused by the example thinking #m1 is the form.

    Thanks for your help. That won’t happen again for sure 🙂

    #343340

    Hi aviator21114,

    Glad that the example was helpful for you. Thread closed.

    #343350

    Robert Gardner
    Participant

    Well, I’m testing variations of using the checkbox value… Why is it when I place the value of the checkbox into a variable it always says ON regardless of whether the box is checked or not?

    #343355

    Robert Gardner
    Participant

    Is it possible to negate a test of the checkbox value?

    if !($('#m1-DistanceCalc-QQ_PeakTravel > input').is(':checked'))
        {alert('test checkbox not set')};

    (this doesn’t seem to work)

    Apologies if I should be posting these in a new thread… I thought since they are still along the same subject lines I should continue here. Let me know for future reference.

    Thanks,

    #343365

    Hi aviator21114,

    >Is it possible to negate a test of the checkbox value?
    Yes, it is. You can either set the exclamation mark after the parenthesis or use an else sentence.

    if(!$(‘#m1-DistanceCalc-QQ_PeakTravel > input’).is(‘:checked’)){
    alert(‘test checkbox false’)
    }

    if($(‘#m1-DistanceCalc-QQ_PeakTravel > input’).is(‘:checked’)){
    alert(‘test checkbox true’)
    }
    else{
    alert(‘test checkbox false’)
    }

    >Why is it when I place the value of the checkbox into a variable it always says ON regardless of whether the box is checked or not?
    Do you still have this issue? Can you share where are you testing it? Test Center, Web SIM, Device?(If device, please share model and OS)

    >Apologies if I should be posting these in a new thread…
    There is not a problem.

Viewing 11 posts - 1 through 11 (of 11 total)
Reply To: Testing checkbox value : SOLVED

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