Home > OS >  Text input command aguments
Text input command aguments

Time:10-30

How would I make commands for an input tag. For example, when you type !echo 'test' in an text input it would edit the content of a p tag

I tried this

<input type="text id="input" onchange="update()"/>
<p id="output"></p>
function update(){
  var x = document.getElementById("input").value;
  if(x == "!echo ", args){
    document.getElementById("output").innerHTML = x;  
  }
}

CodePudding user response:

If I understand the question correctly, you want to show the text that appears after the command "!echo". You're very close to getting it done. I've used the startWith method on the string of x to ensure the '!echo' command is at the beginning of the input. If that's true then we strip off the command using the replace method. I hope that's what you're looking for.

function update(){
  var x = document.getElementById("input").value;
  if (x.startsWith("!echo ")) {
    document.getElementById("output").innerHTML = x.replace('!echo ', '');  
  }
}
<input type="text" id="input" onchange="update()"/>
<p id="output"></p>

CodePudding user response:

Your question is unclear AMO. Here's the result if you type !echo 'test' in your input tag. If that's not the result your expect please update your question.

Feel free to add more details if it's not the goal you want. I don't understand exactly what You want to do...

Have a nice day.

    <input type="text" id="input" onKeyUp="update('\'test\'')">
    <p id="output"></p>
       function update(args){
            var x = document.getElementById("input").value;
            if(x == "!echo "  args){
                document.getElementById("output").innerHTML = x;  
            }else{
                document.getElementById("output").innerHTML ="";
            }
        }
  • Related