This is pretty unpleasant. My code worked fine until the last week. I add several text fields to the HTML page when the user changes [using change() ] the value in the drop-down list.
Here's the HTML code snippet:
<div id="files" class="control-group"> <label class="control-label">No. of files</label> <div class="controls" > <select id="files" name="files" class="span3"> <option value="">--Select Option--</option> <?php for($i=1;$i<21;$i++){ ?> <option value="<?php echo $i ?>"><?php echo $i ?></option> <?php } ?> </select> </div> </div> <div class="control-group" id="titles"> <label class="control-label">File Titles</label> <div class="controls" id="titleAdd"></div> </div>
Here is my Javascript / jQuery :
$(document).ready(function(){ $("#titles").hide(); }); var container; // Add & Remove textboxes $("#files").change(function(){ //Remove all textboxes $("#titles").show(); $(container).empty(); $(container).remove(); //"DIV" ELEMENT AND DESIGN IT USING JQUERY ".css()" CLASS. container = $('<div>', {class: 'controls'}); var option = $("#files").val(); for(i=1;i<=option;i++) { // Add a TextBox $(container).append('<input style="display: block;" type=text name="Description[]" class="span3 input-left-top-margins" id="Description' + i +'"' + 'placeholder="File ' + i + ' Title" />'); } $('#titleAdd').after(container); // ADD THE DIV ELEMENT IN THE RIGHT PLACE. });
The most annoying part is that this code worked fine a few days ago.
source share