My Input form are not displaying field values on button clicking!

Html Code:

<form action="" id="form-1"></form>
    <label for="">
        First Name:
    </label>
        <input type="text" name="fname" id="fname" placeholder="">

        <label for="">
            Last Name:
            <input type="text" name="lname" id="lname" placeholder="">
        </label>
        <button class="btn">Click</button>
        <label for="">
            Display Full Name:
            <input type="text" name="fullName" id="fullName" placeholder="">
        </label>
    </form>

JS Code:

let form = document.getElementById('form-1');
let fname = document.getElementById('fname').value;
let lname = document.getElementById('lname').value;

form.addEventListener('submit',function(){
    
    document.querySelector('.btn').addEventListener('click',function(){
        let display = fname.concat(lname);
        document.getElementById('fullName').innerHTML = display;
    });
})
   

Remove this. You’ve ended form tag pretty early.

still not working !!

Still not displaying the values of input field …

its incorrect the way your written it. and also you are trying to access the value when it will be nothing.

do something like this instead:

let form = document.getElementById('form-1');
let fname = document.getElementById('fname')
let lname = document.getElementById('lname');

    
    document.querySelector('.btn').addEventListener('click',function(){
              document.getElementById('fullName').value = `${fname.value} ${lname.value}`;
    });

why attach an event listener inside the scope of another event listener and also when your script is run the value is empty

I mean ! how to place the event listeners ??

I placed exactly like you said :

let fname = document.getElementById('fname')
let lname = document.getElementById('lname');

    
    document.querySelector('.btn').addEventListener('click',function(){
              document.getElementById('fullName').value = `${fname.value} ${lname.value}`;
    });

But the values only display just for few seconds…

are you using something like codepen? if you have your setting set to update automatically when you make changes to your code then it will do that. that would be the expected behavior…

for me its working as expected:

https://codepen.io/kravmaguy/pen/gOLramJ

Yeahhh !! its working in codepen … but not in visual studio code browser

I think you’re closing form tag two times