Here, you will see how to create multiple TextBoxes and Tabs dynamically using jQuery scripts and CSS.
I hope this code is very helpful for creating a paper format for an online examination project. Check it out. If you have any concerns then let me know.
1. Add CSS and JavaScript file references
I need to add a CSS and jQuery reference to create a tab on a page:
- <link href="css/jquery-ui-1.9.2.custom.min.css" rel="Stylesheet" type="text/css" />
- <script src="jquery/jquery-1.8.3.js" type="text/javascript"></script>
- <script src="jquery/jquery-ui-1.9.2.custom.min.js" type="text/javascript"></script>
2. Create a UI for entering the number of TextBoxes you want to generate, also create the tabs
I use a table for creating a TextBox and a Button. The following figure shows the structure table:
- <body>
- <form id="form1" runat="server">
- <table>
- <tr>
- <td>
- <asp:Label ID="lbltextno" runat="server" Text="Enter Number Of TextBox"></asp:Label>
- </td>
- <td>
- <input type="text" id="txtpaper" />
- </td>
- <td>
- <input type="button" value="Click" id="show" onclick="GetTextBox()" />
- </td>
- </tr>
- </table>
And after creating the table for entering the number of TextBoxes you want to generate, I use an unordered list to create the tabs.
The following figure shows the structure of the unordered list for the tabs:
- <div id="tabs" style="display:none">
- <ul>
- <li><a href="#part1">Part1</a></li>
- <li><a href="#part2">Part2</a></li>
- <li><a href="#part3">Part3</a></li>
- <li><a href="#part4">Part4</a></li>
- </ul>
3. Contents For Tabs
In these tabs I need to generate a TextBox limited in size, in other words the first tabs show only 5 TextBoxes and if you want to create more than show tab2 and greeted than 5 data are shown in the next tabs, tab2, tab3 & tab4. At end of the TextBoxes show, the submit button.
For this, we generate a div in a div.
The following figure shows the structure of the Content for tabs:
- <div id="part1">
- <div id="part1btn"></div>
- </div>
- <div id="part2">
- <div id="part2btn">
- </div>
- </div>
- <div id="part3">
- <div id="part3btn">
- </div>
- </div>
- <div id="part4">
- <div id="part4btn">
- </div>
- </div>
4. Use Of Tabs
Using tabs dynamically generates TextBoxes that are not shown together, they are divided by tabs.
5. Entire Code 6. Output
This output means, if you enter 1 to 5 then TextBoxes not show min 6 required and that means 6 question format show 36 TextBoxes show.
1st for Question,
2nd for Answer2,
3rd Answer3,
4th Answer4,
5th Correct Answer
In this ans1, 2, 3, and 4 are options.