Topic
  • 5 replies
  • Latest Post - ‏2013-05-13T12:58:38Z by Paul Mendelson
MattNa
MattNa
125 Posts

Pinned topic Java script for Checkboxes

‏2013-04-30T22:39:30Z |

I have taken some code I found on a website and modified it so it works the way I need it to, have some issues where the code seems not to work when I try to add a second set of checkboxes

 

Ideas

Attachments

  • Paul Mendelson
    Paul Mendelson
    61 Posts

    Re: Java script for Checkboxes

    ‏2013-05-01T19:37:08Z  

    Hey, that looks really familiar. It's about time I revisited that script - I've learned a lot since I wrote it.

     

    As a quick fix, change

    function selectInCheckbox(id)
    {
       var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(id)
    {
        var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
        inputs[id].click();
    }
     

     

    to:

    function selectInCheckbox(checkbox,id)
    {
       var inputs= document.getElementById(checkbox).getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(checkbox,id)
    {
        var inputs= document.getElementById(checkbox).getElementsByTagName('input');
        inputs[id].click();
    }

     

    Then in the HTML item that contains onClick="selectInCheckboxRow(' to onClick="selectInCheckboxRow('checkboxlist1','

    This way you're passing the ID of the checkbox group to the function, allowing it to reference the correct prompt.

  • MattNa
    MattNa
    125 Posts

    Re: Java script for Checkboxes

    ‏2013-05-01T20:32:08Z  

    Hey, that looks really familiar. It's about time I revisited that script - I've learned a lot since I wrote it.

     

    As a quick fix, change

    function selectInCheckbox(id)
    {
       var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(id)
    {
        var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
        inputs[id].click();
    }
     

     

    to:

    function selectInCheckbox(checkbox,id)
    {
       var inputs= document.getElementById(checkbox).getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(checkbox,id)
    {
        var inputs= document.getElementById(checkbox).getElementsByTagName('input');
        inputs[id].click();
    }

     

    Then in the HTML item that contains onClick="selectInCheckboxRow(' to onClick="selectInCheckboxRow('checkboxlist1','

    This way you're passing the ID of the checkbox group to the function, allowing it to reference the correct prompt.

    This is problem I am now seeing.  It seems to select the first item in the list after the apply button is selected. Ideas why. And the Select all does not work know looking into this

    Attachments

    Updated on 2013-05-01T20:34:34Z at 2013-05-01T20:34:34Z by MattNa
  • MattNa
    MattNa
    125 Posts

    Re: Java script for Checkboxes

    ‏2013-05-09T14:48:38Z  

    Hey, that looks really familiar. It's about time I revisited that script - I've learned a lot since I wrote it.

     

    As a quick fix, change

    function selectInCheckbox(id)
    {
       var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(id)
    {
        var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
        inputs[id].click();
    }
     

     

    to:

    function selectInCheckbox(checkbox,id)
    {
       var inputs= document.getElementById(checkbox).getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(checkbox,id)
    {
        var inputs= document.getElementById(checkbox).getElementsByTagName('input');
        inputs[id].click();
    }

     

    Then in the HTML item that contains onClick="selectInCheckboxRow(' to onClick="selectInCheckboxRow('checkboxlist1','

    This way you're passing the ID of the checkbox group to the function, allowing it to reference the correct prompt.

    Hi Paul I am enclosing my copy of the report I develop with the adaption of the code, while I can get the static table to respond correctly I am using a stored proc and it seems to highlight the top selection as shown before ideas.

     

    Attachments

  • MattNa
    MattNa
    125 Posts

    Re: Java script for Checkboxes

    ‏2013-05-09T16:58:06Z  

    Hey, that looks really familiar. It's about time I revisited that script - I've learned a lot since I wrote it.

     

    As a quick fix, change

    function selectInCheckbox(id)
    {
       var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(id)
    {
        var inputs= document.getElementById('checkbox1').getElementsByTagName('input');
        inputs[id].click();
    }
     

     

    to:

    function selectInCheckbox(checkbox,id)
    {
       var inputs= document.getElementById(checkbox).getElementsByTagName('input');
       for (var i=0;i<inputs.length;i++)
       {
            if (inputs[i].value == id)
            {
                inputs[i].click();
            }
       }
    }
     
    function selectInCheckboxRow(checkbox,id)
    {
        var inputs= document.getElementById(checkbox).getElementsByTagName('input');
        inputs[id].click();
    }

     

    Then in the HTML item that contains onClick="selectInCheckboxRow(' to onClick="selectInCheckboxRow('checkboxlist1','

    This way you're passing the ID of the checkbox group to the function, allowing it to reference the correct prompt.

    Hi Paul

    I have figure out the issue now it is to come with the solution

    case when (ParamValue('p_Scenarioid') +', ') contains (number2string([Scenario Id]) +', ') then (' checked ') else ('') end

    This code a single selection is picked up and the number of spots it uses to 122, 122 and then it picks up the last character

     

  • Paul Mendelson
    Paul Mendelson
    61 Posts

    Re: Java script for Checkboxes

    ‏2013-05-13T12:58:38Z  
    • MattNa
    • ‏2013-05-09T16:58:06Z

    Hi Paul

    I have figure out the issue now it is to come with the solution

    case when (ParamValue('p_Scenarioid') +', ') contains (number2string([Scenario Id]) +', ') then (' checked ') else ('') end

    This code a single selection is picked up and the number of spots it uses to 122, 122 and then it picks up the last character

     

    I haven't forgotten about you.

     

    In my free time I've been rewriting the code to make it more portable and work with multiple lists now. There is one bug that I'm trying to fix, when checkboxes are in groups.