• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 547
  • Last Modified:

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.
0
sammySeltzer
Asked:
sammySeltzer
  • 3
  • 3
1 Solution
 
informaniacCommented:
<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

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

var txtBox = document.getElementByID(txtBoxID);
0
 
informaniacCommented:
Are you getting txtBoxID as null?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
informaniacCommented:
Oh. I just realized the problem

var txtBox = document.getElementById(txtBoxID);

instead of

var txtBox = document.getElementByID(txtBoxID);

capital D was the issue
0
 
sammySeltzerAuthor Commented:
Fantastic job, it worked!!!!

Thank you very much.
0
 
sammySeltzerAuthor Commented:
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
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now