Suppose I have UI like it:

  var someFunction(){
    //some code to validate and then send message
<input type="button" id="submit" value="Submit" onclick="someFunction()"/>

Which a submit button calls someFunction() to validate and then send messages to server. I know someFunction is not a good name for name, but I don't know which naming principle is better: Should the name be:

1.Relate to which button to use:

var onSubmitPressed(){
  //some code to validate and then send message

2.Relate to the task of the function:

var validateAndSendMessage(){
  //some code to validate and then send message

which one is better?

1 Answer 1


It will be good if you give the name same as the action you will be doing. Like if you want to validate and send message to server then the name should be


So whenever if new developer sees your code he will get to know for which purpose this function is written.

  • Yes! Intent should be communicated. But I would go for validate, since the function should validate and in case of successful validation, the browser should "submit" aka "send the message" May 7, 2018 at 10:35
  • 1
    The main question was stating to validate and then send messages to server so I kept such name.. If it was only for validate then we can give the name as validate() or formValidation() May 7, 2018 at 11:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.