Link to home
Start Free TrialLog in
Avatar of sammySeltzer
sammySeltzerFlag for United States of America

asked on

I need a helping set of eyes trying to figure out why my code isn't working.

I have these controls on my gridview markup page.

                  <ItemTemplate> 
                   <asp:CheckBox ID="ckb" runat="server" onclick="Box_Click(this)" /> 
               </ItemTemplate>  
 
                  <ItemTemplate> 
                   <asp:TextBox runat="server" style="border: none;" ID="currentDate"></asp:TextBox> 
                 </ItemTemplate>

Open in new window


Then this js:

function Box_Click(cb) { 
        var tr = cb; 
        var inps = tr.getElementsByTagName("input"); 
        if(cb.checked == 1){ // CheckBox checked condition 

                while (tr.tagName != "TR") { 
                        tr = tr.parentNode; 
                        if (tr == null) return; // something went wrong 
                } 
                for (var i = 0; i < inps.length; ++i) { 
                        var inp = inps[i]; 
                        if (inp.name.indexOf("currentDate") >= 0) { 
                                inp.value = getDate(); 
                                break; 
                        } 
                } 
        } 
        else{ 
                for (var i = 0; i < inps.length; ++i) { 
                        var inp = inps[i]; 
                        inp.value = ''; 
                } 
        } 
}

Open in new window


What I am trying to accomplish really is to allow users to click a checkbox and have current date get inserted into the currentDate control.

Then if the users decide to uncheck the checked box(es), the inserted dates get removed.

I am not getting any errors. However, when you click any checkbox, no date is getting inserted and of course none is getting removed since none is inserted.

I have been looking at this for 2 hours.

Any assistance is greatly appreciated.
Avatar of Obadiah Christopher
Obadiah Christopher
Flag of India image

<ItemTemplate> 
         <asp:CheckBox ID="ckb" runat="server" onclick="Box_Click(this,this.id)" /> 
 </ItemTemplate>  

Open in new window


function Box_Click(cb,cbID) { 
           var txtBoxID = cbID.replace("ckb","currentDate");
           var txtBox = document.getElementByID(txtBoxID);
           if(cb.checked == true)
           {
                          txtBox.value = getDate();
           }
           else
           {
                          txtBox.value="";
           }
}

Open in new window

Avatar of sammySeltzer

ASKER

Error: Object doesn't support this property or method on the following line:

var txtBox = document.getElementByID(txtBoxID);
Are you getting txtBoxID as null?
ASKER CERTIFIED SOLUTION
Avatar of Obadiah Christopher
Obadiah Christopher
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
Fantastic job, it worked!!!!

Thank you very much.
Excellent job. I thought I was good at javascript.

Thank you very much

I will like to make the date persist.

In other words, I am using paging (gridview paging).

When I go to a different page, the inserted dates disappear.

I will like them stay inserted no matter what page you go to until the checkbox is uncheked.

Is this possible?

If yes, pls let me know and I will post the question separately.

Thanks again