CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1
  1. #1
    Join Date
    Jul 2011
    Location
    .NET 3.5
    Posts
    40

    [RESOLVED] Using a variable for getElementById

    I have a checkbox that is being echoed by PHP. So, the id of the checkbox will be dynamic.

    So, I would like use a variable for document.getElementById().

    Below is my PHP code:
    Code:
    echo "<td><input type='checkbox' name='edit$count' value='1' onclick='test($count)'></td>";
    Then here is my Javascript code
    Code:
    function test(v)
            {
                var edit = "edit" + v;
                
                
                if(document.getElementById(edit).checked==true){
                    alert(edit);
                }
            }
    However, when I clicked on the checkbox, there is no alert. Please let me know if there is anything wrong with my code.

    Any help is much appreciated. Thank you.








    EDIT: I found the issue, I am missing an id for the checkbox.
    Last edited by tiestoycc; December 30th, 2012 at 12:49 PM. Reason: SOLVED!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured