Problems with creating dynamically <select/>
<pre><code>&lt;script type="text/javascript"&gt;
    var a = new Array();
    function obj(type, value) {
        this.type = type;
        this.value = value;
        this.toStr = toStr
    }

    function toStr() {
        if (this.type == "select") {
            var temp = "";
            var arr = this.value.split("/");
            for (i = 0; i &lt; arr.length; i++) {
                temp += "&lt;option&gt;" + arr[i] + "&lt;/option&gt;"
            }
            return "&lt;select&gt;" + temp + "&lt;/select&gt;&lt;br&gt;";
        } else
            return "&lt;input type = '" + this.type + "' value = '" + this.value + "'&gt;&lt;br&gt;";
    }

    function addObj(type) {
        var sel = parent.frames["left"].document.form1.q.value;
        for (i = 0; i &lt; sel; i++)
            a[a.length] = new obj(type,
                    parent.frames["left"].document.form1.caption_text.value,
                    a.length);
        paint();
        parent.frames["left"].document.form1.caption_text.value = "";
    }

    function paint() {
        parent.frames["right"].document.open()
        for (i = 0; i &lt; a.length; i++)
            parent.frames["right"].document.writeln(a[i].toStr())
        parent.frames["right"].document.close()
    }
&lt;/script&gt;
&lt;form name=form1&gt;
    &lt;table&gt;
        &lt;tr&gt;
            &lt;td&gt;&lt;input type="button" style="width: 150px" value="Add Button" onClick="addObj('button')"&gt;&lt;br /&gt;
                &lt;input type="button" style="width: 150px" value="Add TexBox" onClick="addObj('text')" /&gt;&lt;br /&gt;
                &lt;input type="button" style="width: 150px" value="Add Select" onClick="addObj('select')" /&gt;&lt;/td&gt;
            &lt;td&gt;Text : &lt;br /&gt; Number of adding elements:&lt;br /&gt;&lt;/td&gt;
            &lt;td&gt;&lt;input type="text" name="caption_text" style="width: 150px"&gt; &lt;br /&gt; &lt;select
                NAME=q size=1 style="width: 150px"&gt;
                    &lt;option selected 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;/select&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;/table&gt;
&lt;/FORM&gt;
</code></pre>

<p><img src="http://i.stack.imgur.com/P8BQe.png" alt="enter image description here"></p>

<p>Code is corrupting when creating select elements.
What's wrong with this code?</p>

<p>Thanks in advance.</p>
