Created
February 21, 2013 19:03
-
-
Save jacoby/5007182 to your computer and use it in GitHub Desktop.
When given an interger (which, yes, I probably need to check against), I create that many DIVs filled with FIELDSETs full of input stuff.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// --------- --------- --------- --------- --------- --------- --------- | |
// function to dynamically create a large number of sample fields | |
// --------- --------- --------- --------- --------- --------- --------- | |
function create_new_samples ( n ) { | |
for ( var i = 1 ; i <= n ; i++ ) { | |
$( '<div\>') | |
.attr( 'id' , 'div_' + i ) | |
.appendTo( '#sample_dump' ) | |
.append( | |
$( '<fieldset/>' ) | |
.text( i ) | |
.addClass( 'number' ) | |
) | |
.append( | |
$( '<fieldset/>' ) | |
.addClass( 'library_name' ) | |
.append( | |
$( '<legend/>' ) | |
.text( 'Library Name' ) | |
) | |
.append( | |
$( '<input type="text"/>' ) | |
.attr( 'id' , 'library_name_' + i ) | |
.attr( 'name' , 'library_name_' + i ) | |
) | |
) | |
.append( | |
$( '<fieldset/>' ) | |
.addClass( 'species' ) | |
.append( | |
$( '<legend/>' ) | |
.text( 'Species' ) | |
) | |
.append( | |
$( '<input type="text"/>' ) | |
.attr( 'id' , 'species_' + i ) | |
.attr( 'name' , 'species_' + i ) | |
) | |
) | |
.append( | |
$( '<fieldset/>' ) | |
.addClass( 'sample_type' ) | |
.append( | |
$( '<legend/>' ) | |
.text( 'Sample Type' ) | |
) | |
.append( | |
$( '<select/>' ) | |
.attr( 'id' , 'sample_type_' + i ) | |
.attr( 'name' , 'sample_type_' + i ) | |
.append( | |
$( '<option/>' ) | |
.val( 'dna' ) | |
.text( 'DNA' ) | |
) | |
.append( | |
$( '<option/>' ) | |
.val( 'rna' ) | |
.text( 'RNA' ) | |
) | |
) | |
) | |
.append( | |
$( '<fieldset/>' ) | |
.addClass( 'notes' ) | |
.append( | |
$( '<legend/>' ) | |
.text( 'Notes' ) | |
) | |
.append( | |
$( '<input type="text"/>' ) | |
.attr( 'id' , 'notes_' + i ) | |
.attr( 'name' , 'notes_' + i ) | |
) | |
) | |
.append( | |
$( '<fieldset/>' ) | |
.addClass( 'control' ) | |
.append( | |
$( '<legend/>' ) | |
.text( 'Control?' ) | |
) | |
.append( | |
$( '<select/>' ) | |
.attr( 'id' , 'control_' + i ) | |
.attr( 'name' , 'control_' + i ) | |
.append( | |
$( '<option/>' ) | |
.val( 'yes' ) | |
.text( 'yes' ) | |
) | |
.append( | |
$( '<option/>' ) | |
.val( 'no' ) | |
.text( 'no' ) | |
.attr( 'selected' , 'selected' ) | |
) | |
) | |
) | |
; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment