Reputation: 127
I want to make dynamic text field named HOLIDAY
after one of data at combo box has selected.
The column which display at combo box is PROBLEM
.
For example I have five problems are A, B, C, D, E.
When I select A problem on combo box, the form edit will display dynamic text field name HOLIDAY
without reload the page. But, If I select B, C, D, E, It doesn`t display. Just A problem which have dynamic text field.
So, how can I solve this problem? What is the code for controller, model, and view on codeigniter?
Upvotes: 0
Views: 1661
Reputation: 1040
Can you try the code bellow:
HTML
<select id="combo" name="combo">
<option value=""></option>
<option value="A">A problem</option>
<option value="B">B problem</option>
<option value="C">C problem</option>
<option value="D">D problem</option>
<option value="E">E problem</option>
</select>
Javascript:
$(document).ready(function(){
$("#combo").change(function(){
var $comboValue = $(this).val();
if($comboValue == "A"){
//Dynamically create the textbox
var $template = "<input type='text' name='HOLYDAY' id='HOLYDAY' placeholder='HOLYDAY' />";
$(this).parent().append($template);
} else {
$("#HOLYDAY").remove();
}
});
});
Here a fiddle to live preview
Regards
Upvotes: 1