Convert Jquery to Motools

65 views Asked by At

In my project motools is used I haven't work with it ever. I have implemented my requirement in Jquery. Can anyone please convert it in motools if you know how to do it?

Here is code:

<input id="txtId" type="text" onkeyup="keywordWithcomma(event , this);"></input>
<div id="res" style="color:red;">Please Enter Keyword less than 15 charactres </div>

JQuery

 function keywordWithcomma(event , obj){
    $('#res').hide();
    reg = /[^a-z,^A-Z^0-9,-, ]/g;
    obj.value =  obj.value.replace(reg,"");
     var txt = $('#txtId').val().split(","); 
     var count = txt[txt.length-1];
     if(count.length>15){
         $('#res').show();
         obj.value =  obj.value.replace(count.substring(14),"");

     }
 }

Working JSFiddle Thanks in advance. :)

1

There are 1 answers

0
Ram On BEST ANSWER

You just use jQuery for showing/hiding the elements and getting value of them. There is no need to use a DOM library for such short snippet, vanilla JavaScript is your friend:

function keywordWithcomma(event, obj) {
     document.getElementById('res').style.display = 'none';
     reg = /[^a-z,^A-Z^0-9,-, ]/g;
     obj.value = obj.value.replace(reg, "");
     var txt = document.getElementById('txtId').value.split(",");
     var count = txt[txt.length - 1];
     if (count.length > 15) {
         document.getElementById('res').style.display = 'block';
         obj.value = obj.value.replace(count.substring(14), "");

     }
}