look at this problem urgent.

2 views
Skip to first unread message

.NetIndia

unread,
Oct 19, 2005, 6:24:43 AM10/19/05
to dotNetIndia
Hi Group
     I am binding a checkboxlist in codebehind. I want to get the
value of each checkbox from javascript. How can I do this?
I tried with the following code

document.getElementById('CheckBoxList1_0').value;

but it is giving the result as on. how to accomplish this one???
--
Sreetharan S.T


--
Regards,
.NetIndia Group,
"There is no delight in owning anything unshared."
"A book lying idle on a shelf is wasted ammunition. Like money, books must be kept in constant circulation. Lend and borrow to the maximum -- of both books and money! But especially books, for books represent infinitely more than money. A book is not only a friend, it makes friends for you. When you have possessed a book with mind and spirit, you are enriched. But when you pass it on you are enriched threefold."

Blog:http://dotnetindia.blogspot.com/

Thread

unread,
Oct 19, 2005, 6:54:43 AM10/19/05
to .NetIndia
this code might help u

function CheckAllDataGridCheckBoxes(aspCheckBoxID, checkVal)
{
re = new RegExp(':' + aspCheckBoxID + '$') //generated controlname
starts with a colon

for(i = 0; i < document.forms[0].elements.length; i++)
{
elm = document.forms[0].elements[i]

if (elm.type == 'checkbox')
{
if (re.test(elm.name))
{
elm.checked = checkVal
}
}
}
}

BabuLives

unread,
Oct 19, 2005, 7:18:09 AM10/19/05
to .NetIndia

Raja Prakash

unread,
Oct 19, 2005, 8:11:45 AM10/19/05
to Techdot...@googlegroups.com
hey.
 
        if you say the purpose then i could say you exact soltuion....
 
byeee...
raj...

 

BabuLives

unread,
Oct 19, 2005, 8:50:07 AM10/19/05
to .NetIndia

veera mani

unread,
Oct 19, 2005, 9:43:21 AM10/19/05
to Techdot...@googlegroups.com
hai raj

iam haveing more 5 items in checkbox list,if zero th item and first item of the
checkboxlist is selected then i should throw an error.this should be
doen in client
side.

--veera.

Thread

unread,
Oct 19, 2005, 11:19:03 AM10/19/05
to .NetIndia
So you are telling that the user can select only one checkbox.

Raja Prakash

unread,
Oct 19, 2005, 3:05:46 PM10/19/05
to Techdot...@googlegroups.com
hey...
 
       great.. wat you have to do is when you are generating the checkbox list you bind it to a javascript function.... in this you pass the object of the checkbox chkList.attributes.add("onclick","return funCheck(this)").  After that you can validate that.  You can use a hidden textbox where you can count how many checkbox is been checked or wat are the check box is checked. on each onclick event of the checkbox you have to check that hidden control if it satisfies your condition throw the error.
 
I hope you got it....
 
          See its like this.... generate as many checkbox you can and you bind all those checkbox to a javascript function by passing them as "this" for onclick event.  chkList.attributes.add("onclick","return funCheck(this)").  in that function check what all the checkbox you have clicked if that satisfies you condition then throw the error and return false else return true.
 
Thats it...
 
byeee
raj...
 

 

ST Sreetharan

unread,
Oct 20, 2005, 12:18:29 AM10/20/05
to Techdot...@googlegroups.com
Hi Rajaprakash
         fine ya, i hope this is a nice solution and this will solve my problem.
 
Thanx a lot
Thank you Group
 
Sreetharan

ST Sreetharan

unread,
Oct 20, 2005, 9:33:21 AM10/20/05
to Techdot...@googlegroups.com
I wrote this code in C#
 
private void Page_Load(object sender, System.EventArgs e)
{
DataSet ds=new DataSet();
ds.ReadXml(Server.MapPath("XMLFile1.xml"));
TableRow tr=null;TableCell tc=null;
CheckBox c=null;int i=0;
foreach(DataRow dr in ds.Tables[0].Rows)
{
c=new CheckBox();tr=new TableRow();tc=new TableCell();
c.Text=dr[1].ToString();
c.ID="Chk"+ (++i).ToString();
c.Attributes.Add("onclick","watchChkList('"+c.ID +"','"+dr[0].ToString()+"');");
tc.Controls.Add(c);
tr.Cells.Add(tc);
Table2.Rows.Add(tr);
}
}
 

and in javascript

<script language="javascript">
  function watchChkList(key,value)
  {
   var existing;
   existing=document.getElementById('hdData').value;
   if(document.getElementById(key).checked==true)
   {
    if(existing !="") existing+=",";
    existing+=value;
   }else existing=existing.replace(value,'');     
   document.getElementById('hdData').value=existing;
  }
  function finalCheck(s,e)
  {
   var existing;
   existing=document.getElementById('hdData').value;
   if(existing.indexOf('J010')>=0 && existing.indexOf('J011')>=0)
    e.IsValid=false;
  }
</script>

Here hdData is a hiddenControl which collects all the values of the checkboxes.

This finalCheck is assigned to a custom validator and it works fine.

Thanks group, for your suggessions

Sreetharan S.T

Reply all
Reply to author
Forward
0 new messages