Entry
how to get elementid by its value/innertext
Jan 4th, 2008 02:05
ashutosh srivastava,
/*comment just copy paste the whole content by deleting all the content
of your asp/html page*/
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs"
AutoEventWireup="false" Inherits="WebApplication3.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<DIV style="DISPLAY: inline; Z-INDEX: 101; LEFT: 328px; WIDTH: 70px;
POSITION: absolute; TOP: 96px; HEIGHT: 15px"
ms_positioning="FlowLayout">
<li id="1" onclick="ashu()">
11111
<li id="2" onclick="ashu()">
222222
<li id="3" onclick="ashu()">
333333333
<li id="4" onclick="ashu()">
4444444
<li id="5" onclick="ashu()">
5555555
</li>
</DIV>
<INPUT style="Z-INDEX: 102; LEFT: 328px; POSITION: absolute; TOP:
232px" onclick="ashu()"
type="button" value="Button">
<script language="javascript">
function ashu()
{
var lii=document.all;
var idofli;
//var op=lii.getElementByValue("a1");
var ra1=document.selection.createRange();
ra1.expand('word');
ra1.select();
alert(ra1.innerHTML);
var ra=document.selection.createRange().text;
var i=0;
//alert();
//alert(document.getElementById("1").innerHTML);
while(lii[i])
{
if(lii[i].innerHTML)
{
if(ra==lii[i].innerHTML)
{
idofli=lii[i];
break;
}
else
{
}
}
else
{
}
i++;
}
alert(idofli.innerHTML+" idofli contains the ID");
if(idofli.style.color=="red")
{
idofli.style.color="black";
}
else
{
idofli.style.color="red";
}
document.selection.empty();
}
</script>
<DIV style="Z-INDEX: 103; LEFT: 192px; WIDTH: 100px; POSITION:
absolute; TOP: 224px; HEIGHT: 100px"
ms_positioning="GridLayout"></DIV>
</form>
</body>
</HTML>