Alpha Video Training
Results 1 to 27 of 27

Thread: Help With Setting Value In Field Based On Checkbox State?

  1. #1
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,642

    Default Help With Setting Value In Field Based On Checkbox State?

    I'm trying to set the value in a Label field to either:
    1. OPERATIONAL if the checkbox is unchecked
    2. NOT OPERATIONAL if the checkbox is checked

    I have this in the OnChange event of the checkbox but it is not working. It always returns 'NOT OPERATIONAL'.

    Code:
    var checked = {dialog.Object}.getValue('SERVICE_STATE');
    
    if (checked = 'true')
    	{dialog.object}.setValue('STATE','NOT OPERATIONAL');
    else if (checked = 'false')
    	{dialog.object}.setValue('STATE','OPERATIONAL');
    Simple component is attached if anyone has time to look.
    Attached Files Attached Files
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  2. #2
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Code:
    if (checked == 'true'){
    	{dialog.object}.setValue('STATE','NOT OPERATIONAL');}
    else if (checked == 'false'){
    	{dialog.object}.setValue('STATE','OPERATIONAL');}
    may be?
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  3. #3
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Try:
    if(checked == true){
    {dialog.object}.setValue('STATE','NOT OPERATIONAL');
    }else{
    {dialog.object}.setValue('STATE','OPERATIONAL');
    }

  4. #4
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,642

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Hmm, well I tried those but no luck .. still won't work.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  5. #5
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    I just tested it. Put it in the click event of the checkbox.

  6. #6
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,642

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    I just tested it. Put it in the click event of the checkbox.
    Really? Wow, this is not working for me!

    Lee, what build are you on?
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  7. #7
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    https://www.screencast.com/t/NTFbekzl

    i just tested with yes value for true for checkbox it works as expected
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  8. #8
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Same version as you. Is your checkbox set as logical?

  9. #9
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,642

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    Same version as you. Is your checkbox set as logical?
    Yes it is.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  10. #10
    "Certified" Alphaholic
    Real Name
    Govindan Gandhi
    Join Date
    Aug 2008
    Location
    New York, NY
    Posts
    4,294

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    if you have set it as logical i would try
    Code:
    if (checked){
    	{dialog.object}.setValue('STATE','NOT OPERATIONAL');
    }
    else {
    	{dialog.object}.setValue('STATE','OPERATIONAL');
    }
    thanks for reading

    gandhi

    version 11 3381 - 4096
    mysql backend
    http://www.alphawebprogramming.blogspot.com
    ggandhi344@gmail.com
    Skype:ggandhi344@gmail.com
    1 914 924 5171

  11. #11
    "Certified" Alphaholic iRadiate's Avatar
    Real Name
    Stephen
    Join Date
    Jan 2011
    Location
    London, ON
    Posts
    1,642

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Okay, I've got it. Where I was getting the value of Service_State, it should have been Machine_State.

    How can I stare at this stuff for an hour and not see that! Sigh.

    Thanks guys.
    Alpha Anywhere v12.4.6.1.2 Build 6012-5338 IIS v8.5 on Windows Server 2012 in Hyper-V

  12. #12
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    It happens to the best of us.

  13. #13
    Member
    Real Name
    Serge Gharibian
    Join Date
    Jan 2017
    Posts
    9

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Hello, I am facing somehow the same problem.
    I have a database in which there is an attribute called 'document', on the UX if the user checks the checkbox the document value should be set to 1, else it should remain 0.
    In the checkbox settings I have set its default value to 0 and the type to logical, however this doesn't work for me.
    If the document value is set to 1, it is changing it to 0, but the opposite doesn't work. When I press the save button it automatically unchecks...

    Can anyone help please?

  14. #14
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Is it code or set to update the database or both?

  15. #15
    Member
    Real Name
    Serge Gharibian
    Join Date
    Jan 2017
    Posts
    9

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    Is it code or set to update the database or both?
    Set to update the database, I haven't added any code to it.

  16. #16
    Member
    Real Name
    Raymond Wang
    Join Date
    Nov 2010
    Posts
    18

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Hello. I'm experiencing the similar issue in my Action Javascript. It seems no matter what the "check' is, it only runs the first If statement.
    I'm trying to replicate a "toggle" to select all checkbox in grid to be on/off. I can't use checkbox select column because I need to have similar functionality for multiple columns in the grid.


    var rowsInGrid = {grid.object}._rowsInGrid;
    var checked = {grid.Object}.getValue('G','PRINTME',1);
    alert (checked);

    if (checked = 'true')
    {
    alert ("Inside True");
    for (var i=1; i <= rowsInGrid; i++)
    {
    {grid.Object}.setValue('G','PRINTME',i,'false');
    }
    }
    else
    {
    alert ("Inside Else");
    for (var i=1; i <= rowsInGrid; i++)
    {
    {grid.Object}.setValue('G','PRINTME',i,'true');
    }
    }

  17. #17
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    try changing this to:
    if(checked == true)

  18. #18
    Member
    Real Name
    Raymond Wang
    Join Date
    Nov 2010
    Posts
    18

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    try changing this to:
    if(checked == true)

    That worked. I'm seeing my alerts of Inside True vs Inside Else. The wierd part is that it only executing {grid.Object}.setValue('G','PRINTME',i,"false");

  19. #19
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Is this line returning a value? "var rowsInGrid = {grid.object}._rowsInGrid;"

  20. #20
    Member
    Real Name
    Raymond Wang
    Join Date
    Nov 2010
    Posts
    18

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    Is this line returning a value? "var rowsInGrid = {grid.object}._rowsInGrid;"
    YES. I'm pulling my hair out. It's driving me crazy!
    I see alert "I am row 1"... to row 147

    else
    {
    alert ("Inside Unchecked");
    for (var i=1; i <= rowsInGrid; i++)
    {
    {grid.Object}.setValue('G','PRINTME',i,'true');
    alert("I am row " + i);
    }
    }

    The javacript by individually is working just fine. Such as Check all ON, Check all OFF.
    I wanted to do a toggle so it's cleaner.

  21. #21
    Member
    Real Name
    Raymond Wang
    Join Date
    Nov 2010
    Posts
    18

    Default Re: Help With Setting Value In Field Based On Checkbox State?


  22. #22
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    I did a little test: This works.
    var rowsInGrid = {grid.object}._rowsInGrid;
    var vchecked = {grid.Object}.getValue('G','CBOX',1);

    if(vchecked == 1){vchecked = 0}else{vchecked= 1}

    for (var i=1; i <= rowsInGrid; i++){
    {grid.Object}.setValue('G','CBOX',i,vchecked);
    }

  23. #23
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?


  24. #24
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Updated for an editable grid: https://www.screencast.com/t/j9TN7NYg

  25. #25
    Member
    Real Name
    Raymond Wang
    Join Date
    Nov 2010
    Posts
    18

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    Quote Originally Posted by lvasic View Post
    Updated for an editable grid: https://www.screencast.com/t/j9TN7NYg
    THANKS YOU SO MUCH, lvasic.

    I love a community who is so passionate to share best practices.

  26. #26
    "Certified" Alphaholic CharlesParker's Avatar
    Real Name
    Charles Parker
    Join Date
    Dec 2012
    Location
    New Orleans, LA
    Posts
    2,115

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    How can I stare at this stuff for an hour and not see that! Sigh.
    Should be my signature...
    Also - good job Lee!
    NWCOPRO: Nuisance Wildlife Control Software My Application: http://www.nwcopro.com "Without forgetting, we would have no memory at all...now what was I saying?"

  27. #27
    "Certified" Alphaholic
    Real Name
    Lee Vasic
    Join Date
    May 2010
    Location
    Salt Lake City
    Posts
    1,209

    Default Re: Help With Setting Value In Field Based On Checkbox State?

    I updated this short video. This is version 3 https://www.screencast.com/t/NEk76cw6mL

Similar Threads

  1. Field validation based on checkbox
    By dfricke10 in forum Application Server Version 11 - Web/Browser Applications
    Replies: 8
    Last Post: 09-17-2014, 11:11 AM
  2. Default field value in grid based on value of checkbox in previously entered field
    By betty in forum Application Server Version 11 - Web/Browser Applications
    Replies: 2
    Last Post: 01-12-2012, 12:26 PM
  3. isblank and checkbox change state problem
    By kavinandi in forum Alpha Five Version 10 - Desktop Applications
    Replies: 1
    Last Post: 02-24-2010, 07:24 PM
  4. Global setting logical field to checkbox
    By Dawnlight in forum Alpha Five Version 7
    Replies: 11
    Last Post: 06-06-2008, 12:45 AM
  5. Setting Values in Sub-Froms based on Parent field
    By paulyp in forum Alpha Five Version 7
    Replies: 4
    Last Post: 01-05-2006, 03:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •