Adding/remving dynamically text boxes I have this coding and I think it works. However, I would like to understand if there is a better way to do this. This would automatically create new textboxes or delete them based on the given selected number.

&lt;script&gt;
    var OLD_CASE_NUMBER = 1;

    $("#cornercases").ready(function () {
        CORNER_CASE_LOADING();
    });
    $("#cornercases").change(function () {
        CORNER_CASE_LOADING();
    });
    // FUNCTIONLITY TO CREATE THE DOWNDOWN MENUS 
    function CORNER_CASE_LOADING() {
        var topvalue = $('#cornercases').val();
        var counter = 0;
        var newvalue = parseInt(OLD_CASE_NUMBER) + 1;

        // ADD MORE VALUES IN CASE

        if (parseInt(topvalue) == 1 &amp;&amp; parseInt(OLD_CASE_NUMBER) == 1)
        {
            var counter = 1;
        var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
            newTextBoxDiv.html('&lt;label&gt;Textbox #'+ counter + ' : &lt;/label&gt;&lt;input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" &gt;');
        newTextBoxDiv.appendTo("#div_selection_section");
        }
        if (newvalue &lt;= topvalue)
        {
            for (counter=newvalue;counter&lt;=topvalue;counter++)
            {
            var newTextBoxDiv = $(document.createElement('div')).attr("id", 'TextBoxDiv' + counter);
                newTextBoxDiv.html('&lt;label&gt;Textbox #'+ counter + ' : &lt;/label&gt;&lt;input type="text" name="textbox' + counter + '" id="textbox' + counter + '" value="" &gt;');
            newTextBoxDiv.appendTo("#div_selection_section");
            }
        }
        else if (parseInt(OLD_CASE_NUMBER) &gt; parseInt(topvalue))
        {
            for (counter=10;counter&gt;topvalue;counter--)
            {
               $("#TextBoxDiv" + counter).remove();
            }
        }
        OLD_CASE_NUMBER = topvalue;
        }
&lt;/script&gt;
&lt;select id=cornercases name=cornercases&gt; 
    &lt;option value="1"&gt;1&lt;/option&gt;
    &lt;option value="2"&gt;2&lt;/option&gt;
    &lt;option value="3"&gt;3&lt;/option&gt;
    &lt;option value="4"&gt;4&lt;/option&gt;
    &lt;option value="5"&gt;5&lt;/option&gt;
    &lt;option value="6"&gt;6&lt;/option&gt;
    &lt;option value="7"&gt;7&lt;/option&gt;
    &lt;option value="8"&gt;8&lt;/option&gt;
    &lt;option value="9"&gt;9&lt;/option&gt;
    &lt;option value="10"&gt;10&lt;/option&gt;
&lt;/select&gt;
&lt;div id='div_selection_section'&gt;&lt;/div&gt;
$(document.createElement('div')). ...


is the same as:

$('&lt;DIV&gt;&lt;/DIV&gt;'). ....




you can just build uppon your previus jQuery statements:

$('&lt;DIV&gt;&lt;/DIV&gt;')
    .attr('id','lol')
    .html('hey hey')
    .appendTo("#div_selection_section");




$("#cornercases").change(function () {
        CORNER_CASE_LOADING();
    });


is the same as:

$("#cornercases").change(CORNER_CASE_LOADING);


and you can bind 2 events in one with jQuery so:

$("#cornercases").bind("change ready",CORNER_CASE_LOADING)




you might want to 
parsInt topvalue in the line with te var

var topvalue = parseInt($('#cornercases').val());


you will not need to repeat pareInt in each 'if' if you do that.

Also, I see that 
OLD_CASE_NUMBER is an integer (and if you do what is mesioned above), you won't need to parse that either



as far as I see the second line of your function var counter = 0; is useless, because everywhere you use counter you first set it to something else