Click to See Complete Forum and Search --> : Handling multiple textbox with same names using Javascript


shiva
11-20-2004, 03:47 AM
Hi

I have a requirement of having multiple textbox in my page.

Since it is created dynamically during runtime the name is same for all the text box.

Now how can i refer the textbox individually.

I want to insert some value into the textbox based on the user choice.

Do you have any idea.

Thanx in advance
shiva

7stud
11-20-2004, 04:22 AM
Since it is created dynamically during runtime the name is same for all the text box.
There is no reason that has to be true:

var name="groupA";
var len=5;
for(var i = 0; i < len ; i++)
{
document.write("<div><input type='text' name='" + name + i + "' /></div>");
}

But, this seems to work just like for radio buttons:

<script type="text/javascript" language="javascript">
<!-- Hide from browsers lacking javascript

window.onload=function()
{
var tb_group=document.forms["f"].elements["tb"];
alert(tb_group[1].value);
};

// End hiding -->
</script>
</head>
<body>

<form name="f" method="post" action="">
<input type="text" name="tb" value="dog" />
<input type="text" name="tb" value="cat" />
<input type="text" name="tb" value="mouse" />
</form>

</body>
</html>