Created
August 25, 2022 06:28
-
-
Save rvvvt/e9b6d35edbe4bd1b5cbb6a9d4d03e988 to your computer and use it in GitHub Desktop.
dynamic user registration form selectable users
This file contains hidden or 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
$(document).ready(function() { | |
$('select#license_qty').change(function() { | |
var sel_value = $('option:selected').val(); | |
if (sel_value == 1) { | |
$("#form_submit").empty(); | |
} else { | |
$("#form_submit").empty(); | |
create(sel_value); | |
$("#form_submit").append($("<button type='submit'>Register " + sel_value + " users</button>")) | |
} | |
}); | |
function create(sel_value) { | |
for (var i = 2; i <= sel_value; i++) { | |
$("div#form_submit").append($("#form_submit").append($("<div style='margin-top:10px;'/>").append($("<h4/>").text("User #" + i)), | |
$('<div/>', { | |
style: 'display:inline-block;' | |
}).append( | |
$("<label>First Name</label>", { | |
for: 'first_name_' + i, | |
class: 'formbuilder-number-label', | |
}), | |
$("<input/>", { | |
type: 'text', | |
name: 'first_name_' + i, | |
id: 'first_name_' + i, | |
class: 'form-control inline', | |
required: '' | |
}), | |
), | |
$('<div/>', { | |
style: 'display:inline-block;' | |
}).append( | |
$("<label>Last Name</label>", { | |
for: 'last_name_' + i, | |
class: 'formbuilder-number-label', | |
}), | |
$("<input/>", { | |
type: 'text', | |
name: 'last_name_' + i, | |
class: 'form-control inline', | |
required: '' | |
}), | |
), | |
$('<div/>', { | |
style: 'display:inline-block;' | |
}).append( | |
$("<label>Email</label>", { | |
for: 'email_' + i, | |
class: 'formbuilder-number-label', | |
}), | |
$("<input/>", { | |
type: 'email', | |
name: 'email_' + i, | |
id: 'email_' + i, | |
class: 'form-control inline', | |
required: '' | |
}), | |
), | |
$('<div/>', { | |
style: 'display:inline-block;' | |
}).append( | |
$("<label>Mobile Number</label>", { | |
for: 'mobile_number_' + i, | |
class: 'formbuilder-number-label', | |
}), | |
$("<input/>", { | |
type: 'tel', | |
name: 'mobile_number_' + i, | |
id: 'mobile_number_' + i, | |
class: 'form-control inline', | |
required: '', | |
minlength: '10' | |
}), | |
), | |
$("<br/><br/>") | |
)) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment