Results 1 to 5 of 5
  1. #1
    sauravsinha is offline Member
    Join Date
    Mar 2010
    Posts
    10
    Rep Power
    0

    Arrow use javascript to enable/disable hyperlinks

    I want to use javascript to decide the behaviours of hyperlink on my jsp page. Actually my requirement is that when the administrator or user login into a system,they both should be directed to the same page suppose homepage.jsp but I want that if the user is administrator then all hyperlinks are enabled and if the user is general then some of the hyperlinks are disabled.Can anybody help me???For any help,thanks a lot in advance.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default

    Post the code how much you tried.Then we will give the solution.
    Ramya:cool:

  3. #3
    sauravsinha is offline Member
    Join Date
    Mar 2010
    Posts
    10
    Rep Power
    0

    Default use javascript to enable/disable hyperlinks

    <script type="text/javascript">
    var user='<%=session.getAttribute("UserName").toString ()%>';
    window.onload=firstLoad;
    function firstLoad()
    {
    if(user=="admin")
    adminload();
    else
    userload();
    }
    function adminload()
    {
    document.getElementById("doc").href = "doctornew.jsp";
    document.getElementById("hos").href = "#";
    document.getElementById("appoint").href = "#";
    document.getElementById("opd").href = "#";
    document.getElementById("search").href = "search.jsp";
    }

    function userload()
    {
    document.getElementById("doc").removeAttribute("hr ef");
    document.getElementById("doc").style.color = "grey";
    //document.getElementById("hos").href ="#";
    document.getElementById("hos").removeAttribute("hr ef");
    document.getElementById("hos").style.color = "grey";
    document.getElementById("appoint").href ="appoint.jsp";
    //document.getElementById("opd").href ="#";
    document.getElementById("opd").removeAttribute("hr ef");
    document.getElementById("opd").style.color = "grey";
    document.getElementById("search").href ="search.jsp";
    }
    </script>


    The HTML code is as follows:-

    <table border="0" cellspacing="0" cellpadding="0" bgcolor="#82CAFF" width=100% height=40px>
    <tr>
    <td width="170px" align="center"><a href="" id="doc">Doctors</a></td>
    <td width="20px" align="center"><img src="images/menu_dividers.jpg" width="1" height="20"></td>
    <td width="170px" align="center"><a href="" id="hos">Hospitals</a> </td>
    <td width="20px" align="center"><img src="images/menu_dividers.jpg" width="1" height="20"></td>
    <td width="170px" align="center"><a href="" id="apppoint">Appointments</a></td>
    <td width="20px" align="center"><img src="images/menu_dividers.jpg" width="1" height="20"></td>
    <td width="170px" align="center"><a href="" id="opd">OPD</a> </td>
    <td width="20px" align="center"><img src="images/menu_dividers.jpg" width="1" height="20"></td>
    <td width="170px" align="center"><a href="" id="search">Search</a></td>
    </tr>
    </table>

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    878
    Rep Power
    11

    Default

    Hi,
    Just check what session.getAttribute("UserName").toString () returns.Might be some space or case problem might be there.trim it and use it with ignorecase functionality.
    Ramya:cool:

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,370
    Blog Entries
    1
    Rep Power
    25

    Default

    Please note that this is Java forum, not a JavaScript forum. There is huge difference between those two technologies. So it's better to discuss you JS related questions in a relevant forum.

Similar Threads

  1. Adding Hyperlinks/Links inside a field of a JTable
    By javanewbie in forum AWT / Swing
    Replies: 3
    Last Post: 05-31-2009, 04:19 AM
  2. Replies: 2
    Last Post: 02-28-2009, 07:30 AM
  3. [SOLVED] hyperlinks in JTextPane
    By olbion in forum New To Java
    Replies: 4
    Last Post: 05-05-2008, 03:28 AM
  4. How to use "selectOneRadio" to enable/disable a Picklist
    By vivekbakshi in forum JavaServer Faces (JSF)
    Replies: 1
    Last Post: 04-07-2008, 03:14 PM
  5. hyperlinks from menu items?
    By asterope118 in forum New To Java
    Replies: 1
    Last Post: 07-16-2007, 01:49 PM

Posting Permissions

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