I have a little form with 3 input type text/number elements and a button.
The script gets the values entered when the user clicks on the button and these values are then appended on a <ul /> <li />
List.
However, the elements appended don't have the jQuery Mobile CSS style.
Here is my Fiddle where you can see the code I have been working on and how it behaves.
I tried using some ideas from This post but no matter how I change it around and adding the $(".config").trigger("create");
(I changed the names to fit my code when testing) it only makes the button
look jQueryMobile style but the remove function doesn't work anymore.
Here's the code (incase you know the solution without looking at the demo):
<input type="text" id="MedNameStren" name="MedNameStren" placeholder="MedName & Strength" />
<input type="number" data-clear-btn="false" id="MedQuantity" name="MedQuantity" min="1" max="50" value ="1" />
<textarea cols="40" rows="4" name="MedDirections" id="MedDiresctions" placeholder="Type any directions written on your prescription for the above medicine." ></textarea>
<input type="button" id="AddScript" data-icon="plus" data-iconpos="right" value="Add New Prescription" />
<ul class="justList"></ul>
$('#AddScript').click(function(){
var text = '<h2>' + $('#MedNameStren').val() + '</h2>' +
'<p><strong>Quantity: </strong>' + $('#MedQuantity').val() + '</p>' +
'<p><strong>Directions: </strong>' + $('#MedDiresctions').val() + '</p>' +
'<button>Delete</button>';
if(text.length){
$('<li />', {html:text}).appendTo('ul.justList')
}
});
$('ul').on('click','button' , function(el){
$(this).parent().remove()
});
Also, it would be nice if you could give me an idea of how to prevent the button from appending a new <li>
if the MedNameStren
and MedDirections
are empty (The spinner will always display a number 1).
Any suggestions or guide will be greatly appreciated!