How to Store CSV Ids in Hidden Field
Script

function AddProjectId(pProjectId) 
{
    var arrProjectIds = new Array();
    var strComma = '';
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvProjectIds = $.trim(csvProjectIds);
    
    if (csvProjectIds != '') 
    {
        arrProjectIds = csvProjectIds.split(', ');
        lngArrLength = arrProjectIds.length;
    } else {
        lngArrLength = 0;
    }
    
    if (arrProjectIds.indexOf(pProjectId) != 0) {
        if (lngArrLength > 0)
            strComma = ', ';
        csvProjectIds = csvProjectIds + strComma + pProjectId;
    }
    
    $('#hdnInterestedProjectIds').val(csvProjectIds);
}

function RemoveProjectId(pProjectId) 
{
    csvProjectIds = $('#hdnInterestedProjectIds').val();
    csvNewProjectIds = '';
    arrProjectids = csvProjectIds.split(', ');
    arrNewProjectIds = new Array();
    lngArrLength = arrProjectids.length;
    
    for (i = 0; i < lngArrLength; i++) 
    {
        if (arrProjectids[i] != pProjectId) 
        {
            arrNewProjectIds.push(arrProjectids[i]);
        }
    }
    
    for (i = 0; i < arrNewProjectIds.length; i++) 
    {
        strComma = '';
        
        if ((csvNewProjectIds != '') && (arrNewProjectIds.length != (arrNewProjectIds.length - 1)))
            strComma = ', ';
        
        csvNewProjectIds = csvNewProjectIds + strComma + arrNewProjectIds[i];
    }
    
    $('#hdnInterestedProjectIds').val(csvNewProjectIds);
}
<input type=”hidden” name=”hdnInterestedProjectIds” id=”hdnInterestedProjectIds”/>

Leave a reply