Reputation: 2371
I´m searchin a JQuery plugin. When I type in a text into a textfield and press a button, the value of the textfield should be shown in a list beneath the textfield.
Does anyone know such a plugin?
Upvotes: 0
Views: 257
Reputation: 189
It's not difficult to write it yourself
<input type="text" id="thisbox" />
<button id="thisbutton" value="click me"></button>
<ul id="listme"></ul>
and the jQuery
$("#thisbutton").click(function(){
var valuebox = $("#thisbox").val();
if(valuebox.length > 0){
$("#listme").append("<li>" + valuebox + "</li>");
}
});
Upvotes: 2
Reputation: 166031
I doubt you will find such a specific plugin, but you could write one yourself. Here's something to get you started (far from perfect, but it should get you on the right track):
(function($) {
$.fn.addToList = function(opts) {
var input = this;
opts.button.click(function() {
opts.list.append("<li>" + input.val() + "</li>");
});
}
})(jQuery);
Assuming HTML like this:
<input type="text" id="example">
<input type="button" id="btn" value="Click">
<ul id="list"></ul>
You would call the plugin like this:
$("#example").addToList({
button: $("#btn"),
list: $("#list")
});
Here's a working example.
Upvotes: 3