rana7cse rana7cse - 2 years ago 68
Javascript Question

How to run a event after write a word in javascript

Hello I have try a lot but can't solve . can any one explain me how I'll drive a JavaScript event after write" in " . I mean i wanted to make a div

after write " in ". that's a auto suggestion issue i've attaching a image the pattern is like that [word] [in] [word].
That's will do

enter image description here

Answer Source

JS version...

var myInput = document.getElementById('myInput');
var messageBox = document.getElementById('messageBox')

myInput.addEventListener("keyup", checkString);

function checkString() {
    var str = myInput.value;
    // notice whitespace either side of "in" to prevent false positives
    if (str.indexOf(' in ') > -1) { 
        messageBox.style.display = "block";
    } else {
        messageBox.style.display = "none";
#messageBox {
    display: none;
    padding: 15px;
    background: #f2f2f2;
    border: 1px solid #e6e6e6;
    margin-top: 15px;
<input id="myInput" placeholder="Type here">
<div id="messageBox">In was typed</div>

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download