Hi,
try the following pattern below, to strip down element in the page if the getElementById method, fails to catch your target object.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>Free Live Help!</title>
<script type="text/javascript">
<!--
var checkObj = function( ids ) { // This will check the object availability in your page
var ids = ids || "";
var index = 2;
var _rate = ids + index;
var obj;
if ( obj = document.getElementById( _rate )) {
return obj;
} obj = document.getElementsByTagName("*");
for ( var i = 0; !!( obj[ i ] ); i++ ) {
/*
If the first statement failed to get the target element, then this block will get executed and will force to return the object by evaluating every ids of the elements' in the DOM collection. */
if ( obj[ i ].id.lastIndexOf("txtrate" + index ) !== -1 ) {
return obj[ i ]; }
} alert( "\nobject id: \"" + _rate + "\" is undefined" );
return false;
};
window.onload = function() {
var element = null;
if ( element = checkObj("ctl00$ContentPlaceHolder1$txtrate"))
element.innerText = "This is your target element: " + element.outerHTML // See if target element returned.
else
return false;
};
// JavaScript-1.5 -->
</script>
</head>
<body id="body">
<!-- DUMMIES -->
<div id="ctl00$ContentPlaceHolder1$txtrate1"></div>
<div id="ctl00$ContentPlaceHolder1$txtrate2"></div>
<div id="ctl00$ContentPlaceHolder1$txtrate3"></div>
</body>
</html>
hope it helps...