How to Dynamically Highlight the selected menu ?

Posted by .Netlearner under JavaScript on 6/19/2012 | Points: 10 | Views : 1450 | Status : [Member] | Replies : 4
Hello All,
Am having menu in the list item as follows

<li id="adminproduct" runat="server"><a id="product" runat="server" href="Product.aspx" onclick="select_func">Products</a></li>
<li id="adminusers" runat="server"><a href="Users.aspx" id="users" runat="server" onclick="select_func1">Users</a></li>
<li id="admincart" runat="server"><a href="myorder.aspx" id="myorder" runat="server">my shopping cart</a></li>
<li id="admincontact" runat="server"><a href="#" id="contact" runat="server">Contact</a></li>


Css is as follows



#menu li a.selected{ /*selected main tab style
background-image: url(../images/shade.gif);*/
background-color: #004d6a;
font-size:12px; font-weight:bold; color:#fff;
border-bottom-color: white;
}


I have used the javascript function with the onclick event as follows,
 <script type="text/javascript">
function select_func()
{
alert("Fired. . ");
document.getElementById("product").className="selected";

}
</script>


But the Script is not getting Fired !

Am I right,Please Guide me how to do ?




Responses

Posted by: Dineshkumarwin on: 6/20/2012 [Member] Starter | Points: 25

Up
0
Down
Try this one

<li id="adminusers" runat="server"><a href="Users.aspx" id="users" runat="server" onclick="select_func()" >Users</a></li>

And my suggestion is to do with JQuery

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Hitesh.Hirpara on: 6/20/2012 [Member] Starter | Points: 25

Up
0
Down
at code behind use this

id.attribute.add("class","class name");

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: .Netlearner on: 6/20/2012 [Member] Starter | Points: 25

Up
0
Down
This too not working i dont know how to handle this i think runat="server" causes a problem with javascript

.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dineshkumarwin on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
<li id="adminproduct" runat="server" ><a id="product" runat="server" href="Product.aspx" onclick="select_func">Products</a></li>

you need to use ClientID in th place of javascript like,

document.getElementById('<%=product.ClientID%> ').propertyName=Value;

because javascript execute at client side.




.Netlearner, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response