Button functionality

what did you try to put there so far?

also, you do not need to necessarily follow all this stuff which was suggested by me

if you followed this video above and maybe done some own research, there are enough info to actually experiment and figure out your own approach to the problem

and don’t feel ‘stupid’, sometimes it takes a while to figure out how all this coding thingies work

1 Like

Im at this stage now, but i really dont know what to do mate , i will soon give up…
I dont know what to do to specify the textfield value?

i get the message textField.value += button.innerText is undefined.

function ready() {

let buttonInputs = '';


let textField;

buttons = document.querySelectorAll(".btn_num")
// console.log(buttons);
inputs = document.getElementsByClassName("form-control num-field")
// console.log(inputs);

buttons.forEach(element => {
element.addEventListener(‘click’, (e)=>{
buttonInputs += element.innerText

        console.log(buttonInputs);
    })

});

  Array.prototype.forEach.call (inputs, (input) => {
 
    input.addEventListener("click", (event) => {
     
      textField.value += button.innerText
      
    })
  })

}
document.addEventListener(“DOMContentLoaded”, ready);

1 Like

here your function receives event parameter.

event itself has a big bunch of properties. Among others, there is target property.

which can be accesssed as event.target.

so intead of this

you can say that

thus, textField will always be the input which was clicked by user

I see you changed code for buttons, that’s not necessary, buttons can deal with textfield, as it was in earlier version of your code

2 Likes

I See, now i understand!

It works now! :smiley:

Thanks alot mate, I really appreciate it!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.