Solution 1 :

It’s getElementsByName. "Elements", plural, as you can have more than one element with the same name. It returns a NodeList, an array like collection of nodes. If you want to grab the first element with that name, you need to access the element at the zeroth index:

const button = document.getElementsByName('form: j_id15')[0]

button.addEventListener('click', (event) => {
  console.log('submit button clicked')
})

// you can use the click() method
button.click()
// or
document.getElementsByName('form: j_id15')[0].click()
<input type="submit" name="form: j_id15" value="Click me" class="btn btn-blue">

PS: If it’s in a form, you should probably subscribe to the form’s submit event, instead of button click.

Problem :

Which function should I use in JavaScript to get the button with name = "form: j_id15"?

I already tried with getElementId, getElementName, but none of them worked. Does anyone have any idea how to do this?

The excerpt from the html page below:

<input 
  type = "submit" 
  name = "form: j_id15" 
  value = "" 
  onblur = "return validarCPFCNPJ (this);" 
  class = "btn btn-blue"
>

Comments

Comment posted by wederfs

The html code of the form already has the button, example of the code in the form: I’m trying to run the javascript command line, on the Chrome console, to click automatically via the command, example: document.getElementByName (“form: j_id15”). Click (); or . Submit; But this command line does not work on the Chrome console

Comment posted by Zsolt Meszaros

I’ve just updated my snippet, you can use

Comment posted by wederfs

It worked now … thank you very much! May God bless you and your family

Comment posted by accept the answer

Great, thank you. If it solved your issue, you could also

By