Skip to content

Instantly share code, notes, and snippets.

@Shadow6363
Created July 22, 2011 17:36
Show Gist options
  • Save Shadow6363/1099931 to your computer and use it in GitHub Desktop.
Save Shadow6363/1099931 to your computer and use it in GitHub Desktop.
Cloning Code
<?php echo $this->Html->script(array('jquery-1.5.1.min', 'surveys'), array('inline' => false)); ?>
<!-- Random Omitted Code -->
<table>
<thead>
<tr>
<th>Type of Agent</th>
<th>List Agent</th>
<th style="text-align: center;">
Biosafety Level<br />
<span style="display: inline-block; width: 23.625%">1</span>
<span style="display: inline-block; width: 23.625%">2</span>
<span style="display: inline-block; width: 23.625%">2+</span>
<span style="display: inline-block; width: 23.625%">3</span>
</th>
<th style="text-align: center;">
<span style="display: inline-block; width: 31.125%">Yes</span>
<span style="display: inline-block; width: 31.125%">No</span>
<span style="display: inline-block; width: 31.125%">NA</span>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td><button id="AddAgent">Add Agent</button></td>
</tr>
</tfoot>
<tbody id="surveyAgents">
<tr id="surveyAgent">
<td><?php echo $this->Form->input('Agent.0.type', array('label' => false)); ?></td>
<td><?php echo $this->Form->input('Agent.0.name', array('label' => false)); ?></td>
<td><?php echo $this->Form->input('Agent.0.biosafety_level', array('legend' => false, 'type' => 'radio')); ?></td>
<td style="margin: 0; padding: 8px 0;"><?php echo $this->Form->radio('Agent.0.yes_no_na', $yesNoNA, $attributes); ?></td>
</tr>
</tbody>
</table>
<!-- Random Omitted Code -->
$(document).ready(function() {
var agentCount = 1;
$('#AddAgent').click(function(event) { event.preventDefault();
$('#surveyAgent').clone(false, false).html($('#surveyAgent').html()).find(':input').each(function() {
$(this).attr('id', $(this).attr('id').replace('0', agentCount));
$(this).attr('name', $(this).attr('name').replace('[0]', '[' + (agentCount) + ']'));
}).end().appendTo('#surveyAgents'); agentCount++;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment