Pergunta

Imagine that I have an input to write words.. and I write "Stackoverflow" (then I click OK button) and a phrase appears down the input area like this one "Stackoverflow, is a place...".

It's nothing like this: http://jqueryui.com/autocomplete/

I want something like this:

<input type="text"/><input type="button" value="OK"/>
<div id="result"/>

Imagine that I write "Password" in the input, and in the result div appears something like "Need password changing? Follow this steps...". Or I write "Admin" and appears "The admin is Nickname". It would be like a mini-bot support.

Foi útil?

Solução

How about something like this (fiddle):

var messages = {
    'stackoverflow': 'Stackoverflow, is a place...',
    'admin': 'The admin is Nickname',
    'password': 'Need password changing? Follow this steps...'
}

var result = document.getElementById('result');
var input = document.getElementById('input');

document.getElementById('submit').addEventListener('click', clickHandler);

function clickHandler() {
    var message = messages[input.value];
    if (message) {
       result.innerHTML = message;       
    } else {
       result.innerHTML = 'String not recognised';   
    }
}

HTML:

<input id="input" type="text"/>
<input id="submit" type="button" value="OK"/>
<div id="result"></div>
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top