Tuesday, November 13, 2012

c# – concatenate values to hidden variable

How to concatenate values to the hdnfield value with comma on checkbox click event. when i click the checkbox i select order and passit to the JS function. If i select three checkboxes the hdnfield value should be like 1, 2, 3… something like that… how to do that?



if (chkBoxOne != null)
{
chkBoxOne.Attributes.Add(\"onclick\", \"javascript:return SelectOne(\'\" + chkBoxOne.ClientID + \"\',\'\" + e.Row.ClientID + \"\',\'\" + lblorderId.Text + \"\')\");
//if (chkBoxOne.Checked)
// hdSelectAllOrderId.Value += ((Label)e.Row.FindControl(\"lblorderId\")).Text + \",\";
}


function SelectOne(id, rowID, OrderID) {
var AllOrderIDs = 0;
AllOrderIDs = Number(document.getElementById(\'ctl00_PagePlaceholder_hdSelectAllOrderId\').value);
alert(AllOrderIDs);
if (document.getElementById(id).checked == true) {
if (AllOrderIDs == \'\')
AllOrderIDs = OrderID;
else
AllOrderIDs = AllOrderIDs + \' ,\' + OrderID;
}
alert(AllOrderIDs);}


The above code is not working. when i click on the firt checkbox its showing frist ordid, but when i click on the second one its not showing first ordid which is i already assigned to it. Its just showing second one…



var AllOrderIDs = 0;
AllOrderIDs = document.getElementById(\'ctl00_PagePlaceholder_hdSelectAllOrderId\').value;
var IDs = AllOrderIDs.split(\',\');
if (document.getElementById(id).checked == true) {
if (IDs.indexOf(OrderID) == -1) {
IDs.push(OrderID);
}
}
else {
var index = IDs.indexOf(OrderID);
if (index != -1) {
IDs = IDs.slice(index, 1);
}
}
AllOrderIDs = IDs.join(\',\');






Rating: 3 out of 5 based on 3 ratings



The post c# – concatenate values to hidden variable appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/c-concatenate-values-to-hidden-variable.html

No comments:

Post a Comment