meowth
meowth

Reputation: 11

How to enter text into a input without using input.value

I have an existing app which requires a user to answer questions using an input box. I did not code this app and I do not want to mess around with the apps code. I have created a virtual on screen numpad from buttons which when pressed add the corresponding value to the input box using '.value'. This does 'work' and the numbers do appear in the input box but they are not saved by the existing code meaning that they mustn't be capturing the '.value'.

Is there some easy way of essentially.. simulating a user inputting text

function geet (clicked_value) {
var input = document.querySelector(".pt-subpage-current input");
if (input.value.length < 3) {
input.value += clicked_value;
}
}
function removeValue() {
var input = document.querySelector(".pt-subpage-current input");
var length = input.value.length;
if (length > 0) {
input.value = input.value.substring(0, length-1);
}
}





<input type="button" onClick="geet(this.value)" value="7" class="button 
number" id="num7" />

Upvotes: 0

Views: 644

Answers (2)

Comet
Comet

Reputation: 298

I literally just made a numpad for someone here. all you need to do is use the showKeyPad() in an onclick event and give the fields id's. Let me know if you need help.

EDIT: Sorry just realized you said it is not saving .value. This keypad uses the .value.

Upvotes: 1

Shubham Dixit
Shubham Dixit

Reputation: 1

You can use div with content editable true ,if that works for you.This is for your simulating part in your question

function edit()
{
let te=document.getElementById("textdiv").textContent;

console.log(te)
}
<div id="textdiv" contenteditable="true">Hello, edit me!</div>

<button onclick="edit()">Button</button>

Upvotes: 1

Related Questions