SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Dec 2008
    Posts
    692
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    making a control visible/ hide in javascript

    i have 2 html tables having as id tb1 & tb2

    i hve 2 asp command buttons on clientclick i want to make it visible & display none

    i have

    function tbl()
    {
    document.getElementById('<%=tbl1.ClientID%>').style.display = 'block';
    document.getElementById('<%=tbl2.ClientID%>').style.display = 'none';

    }

    called on button1 client click as

    cmd.Attributes.Add("onclick", "javascript:tbl()");

    but getting error

    The name 'tbl1' does not exist in the current context

    HTML Code:
    <table width="100%" cellpadding="0" cellspacing="0" id="tbl1">
    <tr>
    <td > one</td></tr></table>
    
    <table width="100%" cellpadding="0" cellspacing="0" id="tbl2">
    <tr>
    <td >two</td></tr></table>

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,117
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    The error means that there's no object in asp called tbl1
    You want to keep your Javascript completely separate to your ASP anyway.

    Code javascript:
    function toggleTables() {
      document.getElementById('tbl1').style.display = 'block';
      document.getElementById('tbl2').style.display = 'none';
    }
    HTML Code:
    <a href="#" onclick="toggleTables(); return false;">toggle</a>


Bookmarks

Posting Permissions

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