Its seems like you really just need to use a loop to output the number of fields that you require.
For example:
You would have a form which would ask the user the amount of fields they need
form.php
<form action="category_form.php" method="get">
Number of fields required:
<select id="num_cat" name="num_cat">
<option value="0">0</option>
<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>
<option value="6">6</option>
</select>
<input type="submit" name="submit" value="Submit"/>
</form>
category_form.php
if(isset($_GET['submit']) && isset($_GET['num_cat'])){
$num_of_fields = $_GET['num_cat']; //WARNING: Requires validation/sanitisation
echo '<form method="post" action="action.php">';
for($i=1; $i<=$num_of_fields; $i++){
echo '<input type="text" name="category-'.$i.'" />';
}
echo '<input type="submit" name="submit" value="Submit"/>';
echo '</form>';
}
HOWEVER, this would be far easier if you used JQuery to dynamically update the amount of fields as this would remove the need to refresh the page. You can do this by using the code below.
index.html
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" ></script>
<script type="text/javascript">
//when the webpage has loaded do this
$(document).ready(function() {
//if the value within the dropdown box has changed then run this code
$('#num_cat').change(function(){
//get the number of fields required from the dropdown box
var num = $('#num_cat').val();
var i = 0; //integer variable for 'for' loop
var html = ''; //string variable for html code for fields
//loop through to add the number of fields specified
for (i=1;i<=num;i++) {
//concatinate number of fields to a variable
html += 'Category ' + i + ': <input type="text" name="category-' + i + '"/><br/>';
}
//insert this html code into the div with id catList
$('#catList').html(html);
});
});
</script>
</head>
<body>
<form method="post" action="action.php">
Number of fields required:
<select id="num_cat" name="num_cat">
<option value="0">- SELECT -</option>
<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>
<option value="6">6</option>
</select>
<div id="catList"></div>
<input type="submit" name="submit" value="Submit"/>
</form>
</body>
</html>
This will then update on the fly instead of having to reload a PHP page every time to generate the fields.
Obviously you will need to add CSS code but im not doing that for you ;).
P.S. Instead of using .keyup you may want to use .change instead...