Getting DataValueField of Checkboxlist Using Javascript

Posted by Sutotpal under Regular Expressions on 3/8/2011 | Points: 10 | Views : 4643 | Status : [Member] | Replies : 4
Hi 2 All,

I binded the Checkboxlist , here
=============================================
chklstAd.DataTextField = "Title";
chklstAd.DataValueField = "ADprice";
chklstAd.DataBind();
==============================================
When i am getting the values onClick of Checkboxlist , i invoke the javascript function , but it returmn the "On" insted of Datavalue.
How can i get the value of DataValueField of Checkboxlist .

Best Regards,
Sutotpal



Responses

Posted by: Prabhakar on: 3/8/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
HI Sutotpal

show ur java script code . . so i try it . .

Best Regard's
Prabhakar

Sutotpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sutotpal on: 3/8/2011 [Member] Starter | Points: 25

Up
0
Down
okayyy,,

chk = document.getElementById('chklstAd');
document.getElementById('hdnadvalue').value="";
chklst=chk.getElementsByTagName('input');
for(i=0; i<chklst.length; i++)
{
if(chklst[i].checked)
{
//alert(chklst[i].value);
var price= chklst[i].value.split('-')
// Holding Ad price
document.getElementById('hdnad').value = parseFloat(parseFloat(document.getElementById('hdnad').value) + parseFloat(price[1]));
// Getting AdId value to save in db
document.getElementById('hdnadvalue').value =price[0] + "-";
}
}
document.getElementById('hdnadvalue').value =price[0];
alert(document.getElementById('hdnadvalue').value); // It return "on"

Best Regards,
Sutotpal

Sutotpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 3/8/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down

Hi Sutotpal

i think u mistake in this line with document.getElementById()

document.getElementById('hdnad').value = parseFloat(parseFloat(document.getElementById('hdnad').value) + parseFloat(price[1]));

try this
document.getElementById('chklstAd').value = parseFloat(parseFloat(document.getElementById('chklstAd').value) + parseFloat(price[1]));

Best Regard's
Prabhakar

Sutotpal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sutotpal on: 3/8/2011 [Member] Starter | Points: 25

Up
0
Down
hi,
here this line
var price= chklst[i].value.split('-') 


it's give "on" value
what should i do here to get value while it checked true and go unside the loop.

Best Regards,
Sutotpal

Sutotpal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response