At the moment I am trying to create a form where you can add new fields/sliders based on what you need. The person is able to add their skill name to a textbox and then select on the slider which level they are at with that skill and they can then choose to add another skill if they like.
Then when the user hits the submit button I want to post this data to a php file where I'll be able to handle the rest and insert these details to the database tables which they correspond to.
I have the following code which displays one text box but I'm really in no mans land with jQuery:
<script>
$(function addSlide() {
$( "#slider" ).slider({
value:1,
min: 0,
max: 5,
step: 1,
slide: function( event, ui ) {
$( "#amount" ).val( ": " + ui.value );
}
});
$( "#amount" ).val( ": " + $( "#slider" ).slider( "value" ) );
});
$(document).on('click', '.addNew', function() {
$('#container').append(addSlide);
});
</script>
<div id="container">
<button class="addNew">Add</button>
<form><br><input type="text" name="skill" placeholder="What's your skill?">
<p>
<label for="amount">Skill Level: 1</label>
<input type="text" id="amount" style="border: 0; color: #f6931f; font-weight: bold;" />
</p>
<div id="slider"></div>
</form>
</div>
Thanks in advance, hope you can help!!
I think what you really want is a method at which you can click and add new sliders into the DOM. You will need to re-bind the slide event each time you create an object. Here's a quick writeup:
You simply call it on a container, such as:
Also, please replace
document
with a closer static parent selector, evenbody
.As usual, here's a working jsFiddle