I want to use the value of a HTML dropdown box and create that number of input boxes underneath. I'm hoping I can achieve this on the fly. Also if the value changes it should add or remove appropriately.
What programming language would I need to do this in? I'm using PHP for the overall website.
I would go for jQuery.
To start with look at change(), empty() and append()
http://api.jquery.com/change/
http://api.jquery.com/empty/
http://api.jquery.com/append/
Here is an example that uses jQuery to achieve your goals:
Assume you have following html:
And this is the js code for your task:
You can simplify this code as follows:
Here is a working fiddle example: http://jsfiddle.net/melih/VnRBm/
You can read more about jQuery: http://jquery.com/
you would most likely use javascript(which is what jquery is), here is an example to show you how it can be done to get you on your way
javascript to dynamically create a selected number of inputs on the fly, based on
Mutahhir
answerDoing it in javascript is quite easy. Assuming you've got a number and an html element where to insert. You can obtain the parent html element by using
document.getElementById
or other similar methods. The method assumes the only children of theparentElement
is going to be these input boxes. Here's some sample code:for the select change event, look here: javascript select input event