Home > database >  Arrow Function inside alert box triggering on 'onsubmit' button of a form
Arrow Function inside alert box triggering on 'onsubmit' button of a form

Time:09-04

my this code outputs the function as it is but I want it to return the value of 'p8' id and I want to use arrow function.

<form onsubmit="alert(()=>{document.getElementById('p8').value})">
    <label>PAlindrome</label>
    <input type="text" id="p8"><br>
    <input type="submit">
</form>

CodePudding user response:

You need to call the function. It's done by adding () to the (function).

<form onsubmit="alert((()=>{document.getElementById('p8').value})())">
  <label>PAlindrome</label>
  <input type="text" id="p8"><br>
  <input type="submit">
</form>

Or easier:

<form onsubmit="alert(document.getElementById('p8').value)">
  <label>PAlindrome</label>
  <input type="text" id="p8"><br>
  <input type="submit">
</form>
  • Related