function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lukesh KarmoreLukesh Karmore 

can someone ans me, in which condition we use this keyword "event"

can someone ans me, in which condition we use this keyword "event" see below...... in handleChange  we use word event and  in handleClick we not why

handleChange(event){
   this.searchvalue=event.target.value; 
}
handleClick(){
  if(this.checkError()){
    InputContacts({searchKey:this.searchvalue})
    .then(result=>{
     this.contacts=result;  
     this.error=undefined; 
       })
       .catch(error=>{
         this.error= error;
         this.contacts=undefined;  
       });
      }
      else{
            alert('input should be valid');
      }
}
 Thank You
ANUTEJANUTEJ (Salesforce Developers) 
Hi Lukesh,

>> https://salesforce.stackexchange.com/questions/285295/lwc-events-when-to-use-event-target-value-event-detail-value

You can check the above implementation as it mentions when to use event.target.value & event.detail.value 

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Malni Chandrasekaran 2Malni Chandrasekaran 2
Hi Lukesh,
This event is actually an object containing information about the action that just happened. And passing that as a parameter in handler function is optional.  In your code, "handleChange(event)" handler needed the element on which the action (event) happened (event.target.value) and hence the event parameter is passed. If you dont need the action (event) details, you dont need to pass.

Hope this helps!
Lukesh KarmoreLukesh Karmore
Means whenever action happens on the component
(like onchange)  we have to use event keyword in handlers right malni.
ANUTEJANUTEJ (Salesforce Developers) 
As per the documentation (https://developer.salesforce.com/docs/component-library/documentation/en/lwc/events_handling) use evt.target.value to get the current value of the input field.

So basically when an onchange event or any such event is triggered an event object containing all the parameters is sent to the function so you can use this event object inside the function as a parameter to access these values so that it can be used inside the function.

You can read more in regards to events in JS in this link (https://developer.mozilla.org/en-US/docs/Web/API/Event).

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Lukesh KarmoreLukesh Karmore
Thank you  anutej and malni .. Solved
ANUTEJANUTEJ (Salesforce Developers) 
I appreciate it if you can close the query by marking the best answer. It may help others in the community. Thank You!