2

I have written the code to create text field dynamically. It should create element according to the number that I fill in form's text field, but it is creating only one field. It should create 5 text fields if put 5 in form. What is the problem? Here is the code:

<SCRIPT LANGUAGE="JavaScript">
<!--Hide from old browsers
function createtext(){
var i=0;
var len1=document.getElementById('s');
var len2=len1.value;
for(i;i<len2;i++)
{
var el= new Array();;
el[i]=document.createElement('input');
el[i].type='text';
el[i].name='text'+i;
el[i].size = 10;
document.f1.appendChild(el[i]);
var mybr=document.createElement('<br>');
document.appendChild(mybr);
}
}
</SCRIPT>
</HEAD>
<BODY >
<form action="" method="get" name="f1">
<input type="text" id="s" name="s" value="" onChange="createtext()" >
</form>

1 Answer 1

3
var mybr=document.createElement('<br>');    
document.appendChild(mybr);

should be

var mybr=document.createElement('br');    
document.f1.appendChild(mybr);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.