show hidden div based on user input

Vikash Rai
Vikash Rai used Ask the Experts™
on
i am new to codeigniter, just have 15 days of experience. i have to ask how to implement a div block of input type text for kids name, grade and course base on number of kids entered by parents??
i have a input type " number of kids" and based on that i want to display a div of level and input type according to number of kids entered like if parents entered 3 kids then i want a div with 3 labels and input type of name and grades...please help me
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Multitechnician
Top Expert 2014
Commented:
test page : https://jsfiddle.net/q3ynua4m/

<!DOCTYPE html>
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
    <script>
        jQuery(function($) {
            $("#nbKids").blur(function() {
                var nbKids = $(this).val();
                if(isNaN(nbKids)) {
                    alert("please enter valid number");
                }
                var divs = [];
                for(var i=0;i<nbKids;i++) {
                    divs.push("<div><input name='childname[]'><input name='childgrade[]'><input name='childcourse[]'></div>");
                }
                divs.join("");
                $("#divs").html(divs);
            });
        });
    </script>
</head>
<body>
nb kids :<input type="text" id="nbKids">
<div id="divs"></div>
</body>
</html

Open in new window

Author

Commented:
Thanks alot

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial