Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Checkbox Issue

  1. #1
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Checkbox Issue

    HI ,

    I strucked with the Check box value in my application. I have few fields in my table. One of the field has checkbox. When I am going to edit the other fields in this table. The Checkbox field is checked without doing update on check box field. In the following Code, i have the checkbox field.

    Code:
        buf.append( "<tr>" );
        buf.append( "  <td class=ppolFormPrompt><font color=#DA8009 size=4>*</font>First Name: &nbsp;</td>" );
        buf.append( "  <td class=ppolFormInput nowrap>" );
        buf.append( "    <input class=textInputSmall size=14 name=firstName value='"+c.getFirstName()+"'>" );
        buf.append( "    MI: <input class=textInputSmall size=2 name=middleName value='"+c.getMiddleName()+"'>" );
        buf.append( "  </td>" );
        buf.append( "</tr>" );
        buf.append( "<tr>" );
        buf.append( "  <td class=ppolFormPrompt><font color=#DA8009 size=4>*</font>Last Name: &nbsp;</td>" );
        buf.append( "  <td class=ppolFormInput nowrap>" );
        buf.append( "    <input class=textInputSmall size=26 name=lastName value='"+c.getLastName()+"'>" );
        buf.append( "  </td>" );
        buf.append( "</tr>" );
        buf.append( "<tr>" );  // this is checkbox field
            buf.append( "  <td class=ppolFormPrompt>&nbsp;</td>" );
            buf.append( "  <td class=ppolFormInput nowrap>" );
            buf.append( "    <input type=checkbox name=PRIVATE_CONTACT value='Y' > Private Contact" );         // "+(c.isPrivate()? "checked":"")+"
            buf.append( "    <input type=hidden name=__PRIVATE_CONTACT value=Y>" );
            buf.append( "  </td>" );
            buf.append( "</tr>" );
    
    After doing update in the table here i am going to set into Database.
    Code:
        if ( !_req.getParam("firstName").equals("") ) c.setFirstName( _req.getParam("firstName") );
        if ( !_req.getParam("lastName").equals("") )  c.setLastName( _req.getParam("lastName") );
      if ( _req.getParam("PRIVATE_CONTACT").equals("Y") )
            c.setPrivate(true);
    Here I am updating other fields. but checkbox field store it as 'checked' in database. In this condition if ( _req.getParam("PRIVATE_CONTACT").equals("Y") ) always it is equal to "Y". But it suppose to happend when i checked the checkbox then only it should equal to "Y". without checked the checkbox also the value equal to "Y" .

    Can anybody give me an Idea on this.
    thanks in advance.

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,458
    Thanks
    76
    Thanked 4,373 Times in 4,338 Posts
    The *value* of a checkbox does *NOT* change whether it is checked or not. It is ALWAYS the same value.

    You must test the .checked attribute of the field to find out if it is checked or not.

    But...

    But that is in JavaScript code. And this *is* the JavaScript forum.

    Looking at your code again, I think you are coding in JAVA, in which case you asked in the wrong forum.

  • #3
    New Coder
    Join Date
    Sep 2008
    Posts
    66
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Here i am doing the validation using javascript.

    Code:
    function ppolSubmitContactEdit()
      {
        var ajax_ShowContactCreate_submiturl = 'xhpContactNew.jsp'+genappend_submiturl + '&pc=DETAIL&submitedit=Y';
        var params = ajax_getFormValues( document.ppolSideUpdateForm, null ); // this is formname
          
       if ( $('__PRIVATE_CONTACT').value == 'Y' && $('PRIVATE_CONTACT').checked )
       {
           postXmlHttp( ajax_ShowContactCreate_submiturl+'&'+params, 'ajax_ShowContactCreate_followup()' );
       }
       else
       {
                 this block is executing and here i am passing form values using 'params'    
            if ( $('__PRIVATE_CONTACT').value == 'Y' && !$('PRIVATE_CONTACT').checked )
            {
               postXmlHttp( ajax_ShowContactCreate_submiturl+'&'+params, 'ajax_ShowContactCreate_followup()' );
            }  
            else
            {
               postXmlHttp( ajax_ShowContactCreate_submiturl+'&'+params, 'ajax_ShowContactCreate_followup_PrivateContact()' );
            }
       }
        _gPpolSidebarDisplaying = 'DETAIL';
      }
    in the above js method i am passing form values. but when i didn't check the checkbox how do i pass the Private_contact value as either "N" or "" ??

    can anybody suggest ??


  •  

    Posting Permissions

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