Reputation: 387
I have an example what I got from asking a question here in Stack overflow (Sorry I am new here this is my 2nd question )
Here is the link of that Example :
jsfiddle.net/SpYk3/Pnr3P/
You Will see there have an option for clicking a button and creating a new div with re-nameable texts .This is great already .But I want to add something extra here and if can then it will be great . What I want is : If I create a div with two same name like : if I previously created a div named : "COOL" and if I created a new one, name "Cool" again it will show an warning "This name is Already taken Try new name " .
Is this possible ?? IT will be great if can be done .
Thanks in advance . All the best
Upvotes: 1
Views: 122
Reputation: 1434
You can try this:
$("#results").on("blur", ".new-folder .title-inp", function(e) {
// tells the browser, when user clicks away from input, hide input and show span
// also replaces text in span with new text in input
var ok = true;
var myinput = this;
$('#results .new-folder .title-inp').each(function(index,input){
if(myinput != input
&& $(input).val().toUpperCase() == $(myinput).val().toUpperCase())
{
ok = false;
return false;
}
});
if(ok) $(this).hide().next().text($(this).val()).show();
else alert('repeated name!');
});
Hope it helps!
The working fiddle:http://jsfiddle.net/Wbrj3/4/
Upvotes: 3