...

View Full Version : Checkbox Issue



adusumalli
07-24-2009, 07:15 AM
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.



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.


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.

Old Pedant
07-24-2009, 07:28 AM
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.

adusumalli
07-24-2009, 07:37 PM
Here i am doing the validation using javascript.



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 ??



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum