0

Hi everyone, i need some help trying to achieve the following. Users enter a page and choose from a drop down list for example when they choose 6 then the page should load 6 text boxes. Im also wondering how we would uniquely name each of the textbox's , Eg textbox 1 would have a name of t_1 and the second would be t_2. hope someone can help me out. Im trying to use javascript with html and php as well in some places

Thanks in advance

Anu

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by AleMonteiro
0

Hi there, create the text inputs are very easy.

Check out this example:

<html>
	<script type="text/javascript">
		
		window.onload = function()
		{
			var select = document.getElementById("select");
			var texts = document.getElementById("texts");
			select.onchange = function()
			{
				var val = select.options[select.selectedIndex].value;
				texts.innerHTML = "";
				for(i=0; i < val; i++)
				{
					texts.innerHTML += '<div><input type="text" name="t_' + i + '" value="select_' + i + '" /></div>';
				}
			}
		}
		
	</script>
	
	<body>
		<select id="select" size="1">
			<option value="1">1</option>
			<option value="2">2</option>
			<option value="3">3</option>
			<option value="4">4</option>
			<option value="5">5</option>
		</select>
		
		<hr/>
		
		<div id="texts"></div>
		
	</body>
</html>

It's working, just run it.

Hope it helps.
Seeya.

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.