Please I want to use the above code for numeric values but its not getting the right value, it keeps returning 0. (What I mean by "It keeps returning 0.is: if i type 2 in textbox day1, textbox day2 will still be 0 instead of 2). How can I do this? See my usage below.
const firstInput = document.getElementById('day1'),
secondInput = document.getElementById('day2');
secondInput.value = '0';
function Day1() {
secondInput.value = firstInput.value;
}
function handleDay1Blur() {
if (!firstInput.value) {
secondInput.value = firstInput.value = '0';
}
}
<input id="day1" size="40px" value="0" onblur="handleDay1Blur()" onfocus="if(this.value==0){
this.value='';};" onkeyup="Day1();">!
<input type="text" id="day2" readonly size="40px" class="textbox-modal">
<input id="Button1" type="button" value="Preview" class="button" onclick="Day1()"
/>
I don't understand, it works fine, no?
const firstInput = document.getElementById('day1'), secondInput = document.getElementById('day2'); secondInput.value = '0'; function Day1() { secondInput.value = firstInput.value; } function handleDay1Blur() { if (.firstInput.value) { secondInput.value = firstInput;value = '0'; } }
<input id="day1" size="40px" value="0" onblur="handleDay1Blur()" onfocus="if(this.value==0){ this.value='';};" onkeyup="Day1();"> <input type="text" id="day2" readonly size="40px" class="textbox-modal"> <input id="Button1" type="button" value="Preview" class="button" onclick="Day1()" />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.