Dynamically checking off checkboxes

Hi,
I have a simple form with some checkboxes.  The user checks them off and the values get store in a db.
I like to eat:
Form page:
  <input type="Checkbox" name="fruit" value="apples">apples ....
- apples
- oranges
- bananas
- grapes
So on the edit page if the user has checked off all, but oranges it should be displayed from the db like so:
x apples
- oranges
x bananas
x grapes
I started by doing this, but it doesn't quit cut it.  Maybe merging the values of the form fields and the db fields into one list would work?
<cfoutput query="getinfo">
         <cfif fruit EQ '#fruit#'>
         <input type="Checkbox" name="fruit" value="#fruit#" checked>x apples
         <cfelse>
         <input type="Checkbox" name="fruit" value="#fruit#" >apples
</cfoutput>
Any ideas would be much appreciated!

Database table: fruitChoice
userID apple orange banana grape
x147d
1
0
1
1
a065b
0
1
1
1
t992w
1
0
1
0
Query to fetch data from the database:
<cfquery name="getInfo" datasource="myDSN">
select apple,orange,banana,grape
from fruitChoice
where userID = '#session.userID#'
</cfquery>
Query to insert data into the database:
<!--- I use the submit field, not a checkbox, to verify whether the form has been submitted. If you don't check a checkbox, x, then the variable form.x wont exist when the form is submitted --->
<cfif isDefined("form.sbmt")>
<cfset isAppleChosen=0>
<cfset isOrangeChosen=0>
<cfset isBananaChosen=0>
<cfset isGrapeChosen=0>
<cfif isDefined("form.apples")>
    <cfset isAppleChosen=1>
</cfif>
<cfif isDefined("form.oranges")>
    <cfset isOrangeChosen=1>
</cfif>
<cfif isDefined("form.bananas")>
    <cfset isBananaChosen=1>
</cfif>
<cfif isDefined("form.grapes")>
    <cfset isGrapeChosen=1>
</cfif>
<cfquery name="saveInfo" datasource="myDSN">
insert into fruitChoice (userID,apple,orange,banana,grape)
values ('#session.userID#',#isAppleChosen#,#isOrangeChosen#,#isBananaChosen#,#isGrapeChosen#)
</cfquery>
</cfif>
And, finally, the form
<form>
    <p>
    <cfif getinfo.apple EQ 1>
        <input type="Checkbox" name="apples" checked>apples
    <cfelse>
        <input type="Checkbox" name="apples">apples
    </cfif>
    </p>
    <p>
    <cfif getinfo.orange EQ 1>
        <input type="Checkbox" name="oranges" checked>oranges
    <cfelse>
        <input type="Checkbox" name="oranges">oranges
    </cfif>
    </p>
    <p>
    <cfif getinfo.banana EQ 1>
        <input type="Checkbox" name="bananas" checked>bananas
    <cfelse>
        <input type="Checkbox" name="bananas">bananas
    </cfif>
    </p>
    <p>
    <cfif getinfo.grape EQ 1>
        <input type="Checkbox" name="grapes" checked>grapes
    <cfelse>
        <input type="Checkbox" name="grapes">grapes
    </cfif>
    </p>
    <p>
    <input type="submit" name="sbmt" value="send">
    </p>
</form>

Similar Messages

  • Dynamically checking ID's in a dynamically built table problem ??

    Im creating a table dynamically using JSP and Javascript....
    its a basic loop that goes through 5 iterations...as follows
    what is happening here is it dynamically in the body creates my
    table and when it hits the the row that has i = 1 or i = 3
    it puts out a checkbox on the table....the code between the <%
    and %> is the jsp portion..this runs on a server....I have two strings CheckBox1 and CheckBox3 which get assigned to two different table rows id's ...so for the first row the table gets created with no checkbox strictly text for the second row it has a checkbox and the forth row has one...
    now what I want the code to do...is if the user hits a button on my page...
    I want to call a javascript function that will go thru the rows and determine
    if it has a checkbox and if so....if that checkbox is checked off. The called function obviously will not know the exact id at the time...since this is built dynamically sometimes I will have CheckBox0 containing a checkbox...Ct will all depend on the data...is there a way to check whether a row has an id
    and if so what that id is..and also if it is a checkbox and finally if its checked off ????
    <%! String checkString1 = null;
    String stringInt = null;
    String checkBoxText = "CheckBox";
    int x = 0;%>
    <% for(int i = 0;i < 5; i++)
    {%>
    <%stringInt = (new Integer(i)).toString();
    checkString1 = checkBoxText + stringInt;
    String[] stringnames = new String[2]; %>
    <tr class="checkboxtext" id=chkb1>
    <td width=100 valign="top" nowrap >
    Corporates</td>
    <td width=60 valign="top" >202
    </td>
    <td width=100 valign="top" >111021AC5R</td>
    <td width=190 valign="top" nowrap class="displaytext">
    BRIT TELECOM PLC </td>
    <td width=85 valign="top" align=right>12/15/01
    </td>
    <td width=70 valign="top" align=right>8M</td>
    <td width=70 valign="top" align=right >$105.5000</td>
    <td width=100 valign="top" nowrap align=right>
    12.5000</td>
    <% if(i ==1 | i ==3)
    {%>
    <%stringnames[x] = checkString1;
    System.out.println("your checkstring value is " + checkString1);
    System.out.println("your mmmy value is " + stringnames[x]);
    x = x + 1;
    %>
    <td width=200 valign="top" id=na1 onMouseOver="tryonmouseover(this)"; onMouseOut="nd();">Needs Approval
    </td>
    <td width=20 valign="top" ><Input type="checkbox" value="OFF" Name="check1" id=<%= checkString1 %> onclick="checkboxclickunclick(this)");" onMouseOver="tryonmouseover(this)"; onMouseOut="nd();">
    <%}
    else
    {%>
    <td width=200 valign="top" class="displaytext">Executed
    </td>
    <td width=20 valign="top" class="displaytext">N/A</td>
    <%}%>
    </td>
    </tr>
    <%}%>
    </table>
    further down is this code...
    <td width="33%" align=center ><INPUT TYPE="BUTTON" VALUE="Approve all" id=apprall onclick="window.approveall()" class=actionbutton</td>
    which will call approveall(). This is the function that I want to go
    thru the table rows....and determine if there is a checkbox and whether it was checked off ???? Thanks for any help .....

    I'm not sure myself how to do what you're asking for, but using DOM (Document Object Model) you can gain access to all objects of an HTML document. You should be able to give your table an id and then access all the rows of the table using JavaScript and DOM.
    Or, you could probably just find an easier way to accomplish what you're asking for. Maybe just use the JavaScript onClick event to append your values to the query string, or whatever it is that you're trying to do.

  • Check a checkbox in a jtable in a panel from another panel

    I have a panel-> Panel A
    where I have some conditions and on that condition I want to check a checkbox in a jtable in another panel ->PanelB
    So Panel B has a jtable with one column as checkbox,I want to check/uncheck this checkbox based on some conditions in some other panel A
    I have no idea how to do this.Please help.
    Thanks

    885522 wrote:
    How will the change be reflected dynamically if the value changes in some other panel.By code that you write. If you want component X to change based on some changes to component Y, then first you set up a listener which will notify you when changes to component Y take place. In that listener you put code which makes the appropriate changes to component X, based on what happened to component Y.

  • How to check whether checkbox is checked or not and to get label if checked

    Hi,
    I've used checkboxgroup, and i'm populating it dynamically using attribute node & attribute value.. like this
    IPrivateTestView.IWelcomNode wNode =wdContext.nodeWelcom();
         IPrivateTestView.IWelcomElement wEl,wE2,wE3;
         wEl=wNode.createWelcomElement();
         wNode.addElement(wEl);
         wEl.setWelValue("Welcome Boards");
         wE2=wNode.createWelcomElement();
         wNode.addElement(wE2);
         wE2.setWelValue("Traditional Welcome");
         wE3=wNode.createWelcomElement();
         wNode.addElement(wE3);
         wE3.setWelValue("Photograph");
    now i want to check whether checkbox is checked and how many checkbox has been checked and then i want that label values of checked boxes.. so pls help me out. if possible give me some sample coding...

    CheckBoxGroup.texts -> Welcom.WelValue
    In controller method (e.g. action handler):
    IWelcomNode node = wdContext.nodeWelcom();
    for (int i = 0; i < node.size(); ++i)
      IWelcomElement e = node.getWelcomElementAt(i);
      if (node.isMultiSelected(i))
        String text = e.getWelValue();
        /* checkbox #i is selected and variable "text" contains the text */
    Armin

  • Dynamic Object for Checkbox in HTMLB control

    Hi all,
    I want to create dynamic object for Checkbox in HTMLB control.
    I have created dynamic check box in JSP using JSPDynpage. I can select multiple values in the list of checkbox.After clicking the submit button , I have to read the value of checkbox.  For this first i want to create the object for checkbox in controller.
    How can i create the dynamic object?
    Help me in this regard.
    Thanks & Regards
    Hemalatha J

    Krish
      Will this link helps you ????
      <a href="http://help.sap.com/saphelp_nw04/helpdata/en/7d/9b0e41a346ef6fe10000000a1550b0/frameset.htm">Check Box</a>
    Thanks
    Jack
    Allot points if it helps

  • Dynamically Turning Off Validation

    I am using several h:inputTextArea's backed by an HtmlInputTextarea's in my page. The 'required' attributes are set to 'true'. The page also has a command button ('backBtn') that takes the user to the previous JSF page.
    The problem is that because of the validation, the user cannot go 'back' unless all the inputTextArea's have data.
    Is it possible to disable validation dynamically? I have tried this code ... :public String backBtn_action() {
        // User event code here...
         disableValidation = true;
         return "back";
    protected void beforeProcessValidations() {
         if (disableValidation) {
             firstNameTF.setRequired(false);
    protected void afterProcessValidations() {
         if (disableValidation) {
             disableValidation = false;
    } ... but it does not work. The validation error still occurs.
    This issue is a significant hurdle in my application. Any help would be much appreciated.

    Simply set the "immediate" property to true (by
    y checking its checkbox in the property sheet), and
    your backBtn_action() will be called during Apply
    Request Values phase instead of waiting until Invoke
    Application. What is more important, this will also
    cause Process Validations, Update Model Values, and
    Invoke Application to be skippedThank you, this is enlightening. I think I see what my issue really is (see below).
    -- which is exactly
    what you want for something like a "Back Button".
    If your application needs a Cancel button, you would
    want to do the same sort of thing, because the user
    is saying "please throw away the values I have
    entered on this form", so validation would not be
    desireable.At least in my case, I see a fundamental difference between Back and Cancel. While Cancel should throw away the data, I need Back to save the state of user input. This way when the user returns to the page (i.e., goes 'forward' again), the components are populated with previous input (he does not have to enter data into ten text fields again). However, as I understand it, for the data to be saved between pages UpdateModelValues must be called, but this phase is skipped when 'immediate' is true. ('Immediate=true' works for Cancel because if the user returns to the page, you want a blank slate).
    So far, am I understanding correctly? Assuming that I am, I tried this approach:
    Using 'Immediate=true' for the backBtn, I tried to manually set values in the bean value-bound to the textfield (since UpdateModelValues is not called to do this for me). This should save the state of the component to be redisplayed:public String backBtn_action() {
        // User event code here...
        getPresenterBean().setFirstName(
            (String)getFirstNameTF().getValue());
            return "back";
    }This does not work - upon returning to the page after going Back, the textfield is empty (perhaps the action is called to early in ApplyRequestValues for this to work?).
    This problem is real road block in time sensitive project. Any further help would be much appreciated.

  • Only allow datagridviewcheckbox to check off if it meets certain criteria.

    I have a datagridview with a checkbox column next to it. The datagridview holds a list of all open invoices for a given customer. I don't want the checkbox to check off if there is no money to apply to this invoice. Basically every time the checkbox is
    unchecked and the user is trying to check in the check box it should check if there is money to apply if yes then check it off if not then it should give a message that it can't check off.
    Debra has a question

    I have a datagridview with a checkbox column next to it. The datagridview holds a list of all open invoices for a given customer. I don't want the checkbox to check off if there is no money to apply to this invoice. Basically every time the checkbox
    is unchecked and the user is trying to check in the check box it should check if there is money to apply if yes then check it off if not then it should give a message that it can't check off.
    Debra has a question
    Hello,
    You could consider doing that task inside CellValidating event like the code below.
    private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
    { //make sure the cell belongs to the checkboxColumn
    if (e.ColumnIndex ==0 && e.RowIndex >-1 )
    { //check whether it meets certain criteria here
    if (Convert.ToInt32(this.dataGridView1.Rows[e.RowIndex].Cells["criteria"].Value) < 2)
    dataGridView1.CancelEdit();
    MessageBox.Show("It doesn't meet");
    The line dataGridView1.CancelEdit(); will stop the checking and return to original value.
    You could place the opinion with your line instaed.
    Regards,
    Carl
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Disabling input text component on checking the checkbox

    Hi,
    I have created INPUT TEXT and CHECKBOX dynamically by the following code.
    List<UIComponent> children;
    children = pgl.getChildren();
    RichPanelGroupLayout pgll;
    pgll = new RichPanelGroupLayout();
    pgll.setLayout("horizontal");
    List<UIComponent> children1;
    children1 = pgll.getChildren();
    RichInputText it;
    it = new RichInputText();
    UIComponent cb = new RichSelectBooleanCheckbox();
    children1.add(it);
    children1.add(cb);
    children.add(pgll);
    Now on checking the checkbox i shud disable the inputtext box.. can someone help me out in getting it?

    In the valueChangeListener of the checkbox, set the disable propoerty of the input box to true and call the partial trigger on the input box using AdfFacesContext.addpartialTarget("idoftheinputbox"). Also set the partial submit of the checkbox to true.

  • Dynamic creation of checkbox

    Hi,
    I want to dynamically create a checkbox in the layout. Can anyone give me sample coding how to create the same. Please don't give me sample coding for creating dynamic buttons as this doesn't work for checkbox.
    Thanks in advance.
    Regards,
    Satheesh Raja.

    Hi,
    attribute_path is something like NODE1.SUBNODE1.ATTRIBUTENAME
    depending on your nodes in your context (what you get in the checked box when you
    declare your checkbox on designtime)
    'attr_ui_element_id'  is your id on your view, this is what you put in the id field in the
    layout pane, naming conventions point at CKB_'name of checkbox' as id,
    if i'm not mistaken.
    m_view is the instance of the view, in wddomodifyview, it's an importing parameter,
    you should bind it there to the attribute m_view in the view attributes.
    put this in wddomodifyview:
    if first_time is not initial.
    wd_this->m_view = view.
    endif.
    and in the attributes pane: m_view type ref to if_wd_view
    grtz
    Koen

  • Dynamic List of Checkboxes and their Default Values

    Hello,
    I have spent more than five hours feebly attempting to figure out how to make a dynamic list of checkboxes (using an LOV) adhere to the values in the database which those checkboxes represent. The LOV itself works; I can get a nice list of checkboxes with the appropriate names, but I can't get HTML DB to check the boxes that have a value of 'Y' in the database. The code for my LOV follows:
    SELECT mesg_name n, mesg_id r
    FROM notifications
    WHERE mesg_id = (SELECT mesg_id
                      FROM subscriptions
                      WHERE upper(network_id) = upper(:APP_USER))Since this is a dynamic list of checkboxes, I obviously cannot use the "Label" property to set the labels of each checkbox. That is what n is in the query above. r is the unique ID of the message (a varchar2) that I will need to pass back to the program after the page is submitted by the user for processing. I cannot take up the value field of the checkbox with a "Y" or something as equally vague. The ID of the subscription that the user is subscribing to or unsubscribing to must be passed back to the program so the appropriate modifications to the database table can be made.
    I would most appreciate it if anyone could lend assistance.
    Thank you,
    Marc Weil

    Marc,
    I think I see what you're trying to do. You'll have to separate process that renders the LOV as a series of check boxes from the process that sets the checked values for each user.
    Before the LOV is rendered on a page, make sure you set the session state value of the LOV item to a colon separated set of IDs based on your query:
    SELECT mesg_id
    FROM subscriptions
    WHERE upper(network_id) = upper(:APP_USER)
    If you have trouble, let me know, I'll try to come up with an example.
    Sergio

  • Apex with dynamic check box....

    hi to all:
    i have report emp.it contain data like eno,ename,sal,record .
    example:eno ename sal record
    100 a 100
    200 b 3000 going on...
    using this column i am making report by using apex and report contain one submit button also.
    1)in this report i am creating dynamic check box depend on eno..see my coding
    declare
    str varchar2(3000);
    begin
    str:='select htmldb_item.CHECKBOX(10,eno,DECODE(record,1,''CHECKED'')) "SELECT" ,eno,ename,sal ,record from emp where 1=1';
    return str;
    end;
    2)in process created after  submit
    iam created pl/code like ..this code for
    declare
    i number;
    str varchar2(2000);
    emp_id number;
    begin
    FOR i in 1..HTMLDB_APPLICATION.G_F10.count
    LOOP
    IF HTMLDB_APPLICATION.G_F10(i) is not null then
    SELECT htmldb_application.G_F10(i) INTO emp_id from dual;
    --insert into my_log values(emp_id);commit;
    update emp set record=1 where eno=emp_id ;
    commit;
    else if HTMLDB_APPLICATION.G_F10(i) is null then
    update emp set record=0 where eno=emp_id ;
    commit;
    else
    null;
    end if;
    end loop;
    end;
    my requirenent:
    a)if check box checked then -update -record column -1
    b)if check box uncked then -update - record column -0
    in process coding--
    eno alway is not null only..
    so i want to do check box with update the record column..like this
    a)if check box checked then -update -record column -1
    b)if check box uncked then -update - record column -0
    pls give solution.
    output i want like this example:
    chebox eno ename sal record
    checked(X) 100 a 300 1
    checked(x) 200 b 300 1
    next time i am trying to make uncheck first row like
    chebox eno ename sal record
    unchecked 100 a 300 0
    checked(x) 200 b 300 1

    Hi VKR,
    Please try this,
    <cfform name="frmTest"  format="Flash" action="test.cfm" method="post"  >
    <cfscript>
        qryCountry = queryNew("Country,CountryID");   
          queryAddRow(qryCountry);  
          querySetCell(qryCountry, "Country", "India");  
          querySetCell(qryCountry, "CountryID", "1");  
          queryAddRow(qryCountry);  
          querySetCell(qryCountry, "Country", "England");
           querySetCell(qryCountry, "CountryID", "2");    
          queryAddRow(qryCountry);  
          querySetCell(qryCountry, "Country", "Kenya");
           querySetCell(qryCountry, "CountryID", "3");      
    </cfscript>   
        <cfformgroup type="repeater"  query="qryCountry">                       
            <cfinput type="checkbox" value="{qryCountry.currentItem.CountryID}" name="chk" Label="{qryCountry.currentItem.Country}">                               
        </cfformgroup>
        <cfinput type="submit" name="submit" width="100" value="Submit"  >
    </cfform>
    Hope this will help

  • I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    I added a contact to my iphone 4s and when I did a sync manually it is not showing up on my MAC in address book - please help....I checked off sync all contacts in iTunes  - does it only work one way from computer to phone?

    Is it because the new itunes looks different.
    View > Show Sidebar
    Then it should work just the same as on your old computer.

  • Perform static and dynamic check together on a customer?

    Hello All,
    Is it possible to perform static and dynamic check together on a customer?
    I believe standard SAP does not allow both options together.
    The scenario is: My client has customer who orders products 1 year in advance and create sales order with a future delivery date. The customer might have balance due on their account which is close to the credit limit. As a result the sale order should be blocked as if the automatic credit check is "Static". This would allow our customer service to call the customer and arrange for the payments.
    Then 11 months later, a dynamic check should be performed on the customer to make sure the past due is under the credit limit. If the past due is over credit limit, the sales order must be blocked for delivery as if the credit check was "Dynamic" with 30 days horizon. This would again give our customer service time to settle the payment with the customer.
    If anyone has implemented such a scenario, can you please give me an overview of how you did it?
    Thanks very much in advance and Text Removed.
    With Regards,
    AM
    Edited by: Lakshmipathi on Nov 13, 2010 9:23 AM
    Please dont include this text

    Static and Dynamic Cannot be Performed together. They are mutually exclusive events.
    Credit check can be performed either at Sale order level or at Delivery / PGI Level.
    FCV3 is a good report to see whether a customer would fail a credit check. ( suitable for your customer service )
    Coming to your Point , Assuming that the customer is eligible for a Credit of 50 Lacs. Now the Customer has placed an order for 60 Lacs. We set the Customer credit checking at  order level . The Customers Sale order would get blocked.
    The Customer service  will follow up for the payment and see to it that it is made. Assume the customer has made a payment for 70 Lacs.
    Now let us have a look at the account statement of the customer.
    Account Statement :     Customer Cr :  70 Lacs.   Dr   :  0.  ( because no delivery and invoice  so far has been made )  
    So we are supposed to deliver the Material worth value of 60 Lacs.
    The First sale order worth 60 Lacs has been unblocked in VKM3. Now at the time of Delivery level why would you want to chekc the Credit limit again ? It has already passed the credit check.
    It is not necessary to check credit limit . Because you have already performed the same at the order level.
    Now the customer has come again and raised another sale order for 80 Lacs. The System would block him.
    The system will never block the Previous delivery which you are, due for delivery  to the customer.
    If we keep on checking the Credits without delivering we would end up only raising in Sale orders and no Delivery to the Customer  at all. The Debit side of his account will always be 0.
    So i donot think Static and dynamic is needed . you can go for either Static or Dynamic.

  • How can I remove music from my iPhone that's not on a playlist, or checked off in the Sync window in any of the possible categories (Playlist, genre, artist, etc)? HELP! It's taking up SO much space on my phone

    How can I remove music from my iPhone that's not on a playlist, or checked off in the Sync window in any of the possible categories (Playlist, genre, artist, etc)? HELP! It's taking up SO much space on my phone but I cannot see a way to remove any of it

    If it's slow on startup it would be extensions loading or LaunchDaemons starting up. 
    You should have a look in:
    /Library/LaunchDaemons
    /Library/Extensions
    You can count out anything in your home folder and it shouldn't put anything in /System as that's reserved for Apple. 

  • I downloaded new os for my daughter's ipod touch.  I remember during setup after that I checked off my husband's email account and now she is receiving his texts.  How do I fix this.  The "icloud"/ "messages" buttons are both greyed out under settings

    I downloaded new os for my daughter's ipod touch.  I remember during setup after that I checked off my husband's email account and now she is receiving his texts.  How do I fix this.  The "icloud"/ "messages" buttons are both greyed out under settings

    Forgotten RESTRICTIONS Passcode
    - Restore from a backup that was make before you added the Restrictions passcode. If you restore from a backup made with the Restrictions passcode the Restrictions passcode is also restored.
    - Restore to factory settings/new iPod.
    - If you are up to file manipulation see:
    How to reset forgotten Restrictions...: Apple Support Communities

Maybe you are looking for