Dynamically added fields not working with calendar field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Beeko
    New Member
    • Jul 2011
    • 1

    #1

    Dynamically added fields not working with calendar field

    I am trying to attach a calendar field to a dynamically added html code. Initially, the code shows 3 input fields (as shown in the "p_scents" div). When the "Add Another Employer" is clicked, it should generate another 3 inputs( as the ones above). It is working fine for me to generate the first 2 fields (without the calendar field), but when I add the calendar field, it is not working.

    Code:
    <h2><a href="#" id="addScnt">Add Another Employer</a></h2>
         <div id="p_scents"> <p>
         <label>Employer Name</label><input class="dynamic" type="text" name="employern" id="employern" />
         <label>Job Title</label><input class="dynamic" type="text" name="jtitle" id="jtitle" />
         <label>Start Date </label> <input type="text" name="startd" class="textfield" />
             <script language="JavaScript">
             new tcal ({
             // form name
             'formname': 'form',
             // input name
             'controlname': 'startd' });
     </script>
     </p>
     </div>
      <script type="text/javascript">
     $(function() {
         var scntDiv = $('#p_scents');
         var i = $('#p_scents p').size() + 1;
          $('#addScnt').live('click', function() {
             if( i <= 10 ) {
                 $('<p><label>Employer Name</label><input class="dynamic" type="text"     name="employern' + i +'" id="employern" /><label>Job Title</label><input class="dynamic" type="text" name="jtitle' + i +'" id="jtitle" /><label>Start Date </label> <input type="text" name="startd' + i +'" class="textfield" />
             <script language="JavaScript">
             new tcal ({'formname': 'form','controlname': 'startd' + i +''});</script><a href="#" id="remScnt">Remove</a></p>').appendTo(scntDiv);
                 i++;
                 return false;
    }
             else{
                 alert('Maximum Reached!');
             }
         });
          $('#remScnt').live('click', function() {
                  if( i > 2 ) {
              $(this).parents('p').remove();
                         i--;
                 }
                 return false;
         });
     });
     </script>
    Last edited by acoder; Jul 4 '11, 02:26 PM. Reason: Added linebreaks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Take the JavaScript code out and add it separately as you did for the initial calendar field.

    Comment

    Working...