Link to home
Start Free TrialLog in
Avatar of patd1
patd1Flag for United States of America

asked on

add comma delimited string to a hiddenfield on my page

I have a gridview that displays client data. The first column on each row for the gridview is a checkbox.  The second column on the gridview is client name and the third column is account holder. The user can select checkboxes (on multiple rows) to modify data (account holder).

I want to add clientName column value in a comma delimited string to a hiddenfield on my page.
How do I do that using javascript, as I do not want to use postback and looping through each row on the grid to get the checkbox status. When a checkbox is checked, it should append the hiddenfield value.

I am a newb on javascript. Please review my javascript code and suggest corrections. I am getting the hiddenfield value as blank no matter what checkboxes are checked. I also know that my code is not targeting the correct row to get ClientName (row where checkbox is checked).

Any help is highly appreciated.

Thanks.

function RowClick(CheckBox) 
        {
            var BaseControl = document.getElementById('<%= this.myGrid.ClientID %>');
            var TargetControl = document.getElementById('MyHiddenField');
            for (var i = 0; i < BaseControl.rows.count; i++)
            {
                var rowElem = BaseControl.rows[i];
                for (var x = 0; x < rowElem.cells.count; x++) 
                {
                    var ClientName = rowElem.cells[1];
                    if (CheckBox.checked) TargetControl.Text += "," + Case_Id;
                }
            }
        }

Open in new window

Avatar of chaitu chaitu
chaitu chaitu
Flag of India image

can you post the view source code??
ASKER CERTIFIED SOLUTION
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patd1

ASKER

Please find attached partial view source code. Pasting the whole thing will make reading it too complicated. Please let me know if you need any other part to help me. Appreciate your help.

Thanks.

<td align="center">
                                    <span id="ctl00_ContentPlaceHolderMain_Error"></span>
                                    <input type="hidden" name="ctl00$ContentPlaceHolderMain$MyHiddenField" id="ctl00_ContentPlaceHolderMain_MyHiddenField" />                                    
                                </td>

....
..
..


</th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$CaseNo&#39;)">Case Number</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$CaseID&#39;)">CaseID</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$ClientName&#39;)">Client Name</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$CompanyName&#39;)">Company Name</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$PatientName&#39;)">Patient Name</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$CreatedDate&#39;)">Created Date</a></th><th scope="col"><a href="javascript:__doPostBack(&#39;ctl00$ContentPlaceHolderMain$gvWorklist&#39;,&#39;Sort$AssignedDoctor&#39;)">Assigned Doctor</a></th>
			</tr><tr>
				<td>
                                                    <input id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl02_CheckBoxActiveClient" type="checkbox" name="ctl00$ContentPlaceHolderMain$gvWorklist$ctl02$CheckBoxActiveClient" onclick="javascript:RowClick(this);" />
                                                </td><td align="left" style="white-space:nowrap;">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl02_LabelCaseNumber">OTH11-000511</span>
                                                </td><td style="white-space:nowrap;">186450</td><td style="white-space:nowrap;">C702</td><td>Georgia Cancer Specialists-Macon Coliseum</td><td>TEST1, Deep </td><td style="white-space:nowrap;">2/15/2011 11:51:33 PM</td><td align="left">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl02_LabelAssignedDoctor"></span>
                                                </td>
			</tr><tr class="alt">
				<td>
                                                    <input id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl03_CheckBoxActiveClient" type="checkbox" name="ctl00$ContentPlaceHolderMain$gvWorklist$ctl03$CheckBoxActiveClient" onclick="javascript:RowClick(this);" />
                                                </td><td align="left" style="white-space:nowrap;">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl03_LabelCaseNumber">OTH11-000509</span>
                                                </td><td style="white-space:nowrap;">186440</td><td style="white-space:nowrap;">C702</td><td>Georgia Cancer Specialists-Macon Coliseum</td><td>TEST, CASE </td><td style="white-space:nowrap;">2/8/2011 6:36:50 PM</td><td align="left">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl03_LabelAssignedDoctor"></span>
                                                </td>
			</tr><tr>
				<td>
                                                    <input id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl04_CheckBoxActiveClient" type="checkbox" name="ctl00$ContentPlaceHolderMain$gvWorklist$ctl04$CheckBoxActiveClient" onclick="javascript:RowClick(this);" />
                                                </td><td align="left" style="white-space:nowrap;">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl04_LabelCaseNumber">OTH11-000508</span>
                                                </td><td style="white-space:nowrap;">186428</td><td style="white-space:nowrap;">C702</td><td>Georgia Cancer Specialists-Macon Coliseum</td><td>TEST, CASE </td><td style="white-space:nowrap;">1/27/2011 5:05:07 PM</td><td align="left">
                                                    <span id="ctl00_ContentPlaceHolderMain_gvWorklist_ctl04_LabelAssignedDoctor"></span>
                                                </td>

Open in new window

SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of patd1

ASKER

used a different solution.