Click to See Complete Forum and Search --> : how to get an index of substring?


advancedobj
12-22-2002, 06:32 AM
Hi,

i have a <div id=test>dynamic string</div>.
inside of <script language="JavaScript">, i want to find an position of a substring from the dynamic string. in java, we have int i = aString.indexof(aSubstring). could you please tell me how it works for the DHTML?
many thanks,

advancedobj

swon
12-22-2002, 06:42 PM
Just little different, it is for example:


<body>
<div id=test>dynamic string</div>
<script language="JavaScript">
<!--
var str = document.getElementById("test").innerHTML;
if(str.indexOf("dy") > -1){
alert("The string has an index of 'dy'");
}
//-->
</script>
</body>

advancedobj
12-23-2002, 12:03 AM
thanks Swon, the problem has been solved.

peterz