CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2005
    Posts
    23

    Disabling menu link

    Hi,

    I'm quite new to JScript and html pages.

    Depending on the selection of the Radio button on a html page a menu item link on the html page has to be enabled or disabled.
    By default the menu item is not to be present and it is only on the selection of the radio button the menu link gets enabled.

    Can anybody let me know how do i mix formatting with Java script. In short how do I check the value of a flag(set on selection of radio button) to determine the appereance of the Menu link.

  2. #2
    Join Date
    Jun 2005
    Posts
    1,255

    Re: Disabling menu link

    Here is an example
    Code:
    <html>
    <head>
    <script language=javascript>
    function enable_link()
    {
       document.getElementById("link1").innerHTML="<a href=\"javascript:alert('Cool');\">Click on this cool link</a>";
    }
    function disable_link()
    {
       document.getElementById("link1").innerHTML="<a disabled><u>It's useless to click on this cool link</u></a>";
    }
    </script>
    </head>
    <body">
    <form>
    <input type=radio name=r1 value=v1 checked onclick="enable_link()">Enable link
    <br>
    <input type=radio name=r1 value=v2 onclick="disable_link()">Disable link
    </form>
    <p>
    <span id="link1"><a href="javascript:alert('Cool');">Click on this cool link</a></span>
    </body>
    </html>

  3. #3
    Join Date
    May 2005
    Posts
    23

    Re: Disabling menu link

    Thanks for the update.
    I was wondering what has to be done so that the link should not be present at all in the document. It is only when the radio button is selected that the link comes on the document.

  4. #4
    Join Date
    Jun 2005
    Posts
    1,255

    Re: Disabling menu link

    In my example above, you replace
    Code:
    function disable_link()
    {
       document.getElementById("link1").innerHTML="<a disabled><u>It's useless to click on this cool link</u></a>";
    }
    by
    Code:
    function disable_link()
    {
       document.getElementById("link1").innerHTML="";
    }
    The principle is that I use a "span" thing (I'm not sure if it is a true "object" or not), named "link1" in my example.
    Then I can put everything I want into that span thing, such as a href link, or nothing, with the "innerHTML" or "innerText" property.
    The span thing is very useful. It is similar to the "div" thing, except that "div" always takes at least an entire line, whereas the span thing has the width of the things it contains.

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