Fill password field programatically like real user [duplicate] - javascript

This question already has answers here:
How can I trigger an onchange event manually? [duplicate]
(2 answers)
How do I programmatically force an onchange event on an input?
(11 answers)
Closed 4 years ago.
I have input field like below
<input type="password" placeholder="Password" autocorrect="off" maxlength="30" autofocus="autofocus" animate="true" label="" rules="[object Object]">
and button like below
<button type="submit" class="button-orange wide">Login <!----></button>
So i am filling password with pure javascript like below
document.querySelectorAll('input[type=password]')[0].value = "12345";
document.querySelectorAll('.button-orange')[0].click();
Problem is the actual website is tracking keydown or something , its always alerting me password is empty also when i focus on input password tab , Password filled getting empty.
How do i fill password like real human typed it.

May be you have to set redOnly property of the field to true after filling it with value by JavaScript
document.querySelectorAll('input[type=password]')[0].value = "12345";
document.querySelectorAll('input[type=password]')[0].readOnly = true;

Related

Sort string based on user input using JavaScript [duplicate]

This question already has answers here:
Sort a string alphabetically using a function
(3 answers)
Change input value onclick button - pure javascript or jQuery
(6 answers)
change value of input field onclick
(5 answers)
Closed 3 months ago.
The question is how to sort the letter in alphabetic order based on the input in a HTML input tag, then clicks a button to sort it, after click the button the input will move to a text area and is already sorted when button is click, so that button need to have the insert function and sorting function, now the input can be insert to the textarea but not sorted, thanks.
Example of input:
andwe
output:
adenw
i want to define my input as an element, and write onclick="sortstring(element of my input)" in button, but i dont know how to define and dont have a sort function yet.
function sortString() {
const inputElement = document.getElementById('input');
const sortResult = inputElement.value.split('').sort().join('');
inputElement.value = sortResult;
}
<input id='input' type="text" value=''/>
<button onclick="sortString()">sort</button>
function sortString(str) {
document.querySelector('#result').innerHTML = str.split('').sort().join('')
}
<input type='text' onkeyup='sortString(this.value)'>
<p id="result"></p>

Get new value from one input to another [duplicate]

This question already has answers here:
How to Copy Value from one Input Field to Another
(2 answers)
Closed 2 years ago.
Let's say I have two inputs in HTML:
<input type="number" id="test1">
<input type="number" id="test2">
Now I've an algorithm which should be called after enter of some number in input. For example, if I enter 10 in first input, in twice input must be returned 5 (10/2) without click of any button. So how to archive that?
You can use the input event listener.
document.getElementById("test1").addEventListener("input", function() {
document.getElementById("test2").value = this.value/2;
})

Paste Only Numbers in Input Field [duplicate]

This question already has answers here:
Putting text in a number input doesn't trigger change event?
(3 answers)
Closed 5 years ago.
I have an Input field in my form. I want to be able to past only numbers in this input field.
For example: (Some random characters on my clipboard W123W000)
Should Paste = 123000
Note: Only works in Chrome Browser
I have been searching online and so far I came up with this but it's not working properly.
var inputBox = document.getElementsByClassName('numbersOnly');
inputBox.onchange = function () {
inputBox.value = inputBox.value.replace(/[^0-9]/g, '');
}
<input id="number" type="number" class="numbersOnly">
Use jQuery for cross-browser compatibility and bind the event input to handle every change.
Firefox: <input type="number">
elements automatically invalidate any entry that isn't a number (or empty, unless required is specified).
You can change to type=text, but you will lose the numeric keyboard behavior in devices.
var inputBox = $('.numbersOnly').on('input', function(e) {
e.preventDefault();
$(this).val($(this).val().replace(/[^0-9]/g, ''));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="number" type="text" class="numbersOnly">

Get the values of two input range with javascript [duplicate]

This question already has answers here:
How do I get the value of text input field using JavaScript?
(16 answers)
Closed 6 years ago.
I have two input type = range:
<input type="range" id="range_1" name="rangeA">
<input type="range" id="range_2" name="rangeB">
I want to get the values and put them in a function.
How can i do that?
first you need to select the input, thankfully you have separate ids on them,
Vanilla JS:
var element = document.getElementById('range1').innerHTML;
Here is a list of stuff you can then do with that element, like innerHTML
https://developer.mozilla.org/en-US/docs/Web/API/Element

Check if input field has focus and pass input variable to function [duplicate]

This question already has answers here:
Using jQuery to test if an input has focus
(15 answers)
Closed 7 years ago.
I have an input field which will be updated every x seconds:
<input type="number" name="METER" id="METER.NUM" min="0" max="500" step="0.10" oninput="setMeter(currentValue);" >
Now, I want to check if the input field has focus (user clicked into the field).
If the field has focus:
I will stop updating the field and the user can put some value into the field
Then the value should be passed to a function
This is the javascript code:
if (document.getElementById(array[0]).name == "METER") {
// check if the input field has focus
// stop updating
}
What's wrong with my approch/code? I think one problem is, that the function call by oninput doesn't work. But it works by onClick.
use onfocus = myFunction()
function setMeter() {
console.log('hey, im focused');
// do stuff here
}
<input type="number" name="METER" id="METER.NUM" min="0" max="500" step="0.10" onfocus="setMeter();" >

Categories