johnny-2step Posted June 29, 2007 Share Posted June 29, 2007 Good day everyone. I'm new to the forums. I just wanted to ask if it is possible in javascript to make a script that when a user clicks a button a new textbox will appear. If he clicks again, another textbox will then appear, so on and so forth. Without having to refresh the page everytime he clicks the button or loose any information he has already typed within the textbox/s. If it is, can anyone give a simple script that I can look into. Much thanks for any help. Quote Link to comment https://forums.phpfreaks.com/topic/57674-create-textbox/ Share on other sites More sharing options...
RichardRotterdam Posted June 29, 2007 Share Posted June 29, 2007 Piece of cake try this <script> function addField(){ var textfield='<input type="text" />'; document.getElementById('dynamic_fields').innerHTML+=textfield; } </script> <div id="dynamic_fields"></div><a href="javascript:addField()">add field</a> Quote Link to comment https://forums.phpfreaks.com/topic/57674-create-textbox/#findComment-285627 Share on other sites More sharing options...
johnny-2step Posted June 29, 2007 Author Share Posted June 29, 2007 Thank you very much, it works great. Didn't know it was that simple. I'll just expound on it for the application I'm building. Again thanks. Quote Link to comment https://forums.phpfreaks.com/topic/57674-create-textbox/#findComment-286268 Share on other sites More sharing options...
RichardRotterdam Posted June 30, 2007 Share Posted June 30, 2007 Do note that the value's in the textfields will be lost when you add a new textfield. This you can solve with a for loop checking every value before adding a new textfield Quote Link to comment https://forums.phpfreaks.com/topic/57674-create-textbox/#findComment-286532 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.