SO - 22004355

by Arun P Johny

HTML

<div id="zero_form" class="zero_form" style="display:none;">
    <p>
        <input id='box1_' type="text" style="width:125px" placeholder='Type'>
        <br>
        <select id='box2_' class="first_input" style="width: 200px;" placeholder="Choose a Value">
            <option value="Choose a Value">Choose a Value</option>
            <option>NEGATIVE</option>
            <option>EQUIVOCAL</option>
            <option>POSITIVE</option>
        </select>
        <input id='box3_' type="text" style='display:none;' class='positive' placeholder='Score #1'>
        <input id='box4_' type="text" style='display:none;' class='positive' placeholder='Score #2'>
        <input id='box5_' type="text" style='display:none;' class='positive' placeholder='%'>
        <input id='box6_' type="text" placeholder="Enter Comments" style="width:200px">
        <input type="button" id="remove" class="removebutton" value="Delete">
        <br>
    </p>
</div>
<!-- end hidden clone div-->
<form>
    <p>
        <span id="add" class="addbutton">Add another row</span>
    </p>
</form>

JavaScript

$(document).ready(function () {
    // show hidden inputs on POSITIVE selection
    $(document).on('change', '.zero_form select.first_input', function () {
        var sel = $(this).val();
        $(this).parent().find('input.positive').toggle(sel == 'POSITIVE');
    });
    $(document).on('click', '.zero_form .removebutton', function () {
        $(this).closest("div").remove();
    });

    // clone fields  
    var form_index = 0;
    $("#add").click(function () {
        form_index++;
        var $from = $("#zero_form").clone().attr("id", "zero_form" + form_index).insertBefore($(this).parent())
        $from.css("display", "inline");
        $from.find(":input").each(function () {
            $(this).attr("id", $(this).attr("id") + form_index);
        });
    });

});