..........//some code//
//here s will be incresed in runtime
var oC2TD = oTR.insertCell(1);
		oC2TD.innerHTML = "<input type=text class=text_box2 autocomplete=off name=txtCatgName"+s+" id=select"+s+"/>";

[B]//for above alert iam getting null
//but when i replace "select" with text box name like txtCatgName
//iam getting object and i replace in below line too, but, if i replace like that, iam not getting customarray data into object in the below line[/B]
var obj = actb(document.getElementById('select'+s+''),customarray);	


i did this in my previous java program, its working, but in other prgrm it's not working

7 Years
Discussion Span
Last Post by essential

Here's a simple demo, that will evaluates all ids of created elements.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<html id="html40L" lang="en">
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<meta http-equiv="Window-target" content="_top">
<title>Free Live Help!</title>
<style type="text/css">

<script type="text/javascript">
var obj = function() {

   var oC2TD = (( document.getElementById ) ? document.getElementById("mydiv") : document.all.mydiv ); // Assuming that this the table-cell.

   var hold = document.createDocumentFragment();
   for ( var x = 0, y = 0; x < 2, y < 3; x++, y++  ) {
   input = document.createElement("input");
   input.id = "select" + y;

   input.type = "text";

   hold.appendChild( input );

   oC2TD.appendChild( hold );
   alert((( document.getElementById ) ? document.getElementById("select" + x ) : document.all["select" + x ]).id );  
window.onload = obj;
// -->
<div id="mydiv"></div>

I think the problem with your code, is that the variable s is incremented more than the numbers of elements created inside your table-cell. But this can be fixed, doing this format:

alert( document.getElementById("select" + (( s ) - 1 )));

hope it helps...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.