Home  >  Q&A  >  body text

How to get input value through onblur event?

I'm trying to get the value input via onblur event but it doesn't work when I use JS module.

<!DOCTYPE html>
<html lang="en">
     <head>
          <meta charset="UTF-8" />
          <meta http-equiv="X-UA-Compatible" content="IE=edge" />
          <meta name="viewport" content="width=device-width, initial-scale=1.0" />
          <title>Calculadora de receitas e despesas</title>
          <script type="module" src="main.js"></script>
     </head>
<body>
  <table> 
      <tr>
               <td >Franchise Fee</td>
               <td class="value">
                    <input type="input" class="form__field" placeholder="R$" name="franchise-fee" id='franchiseFee' onblur="getFranchiseFee()" required />
               </td>
      </tr>
   </table>
</body>

GetElements.mjs module file:

function getFranchiseFee(franchiseFee){
    franchiseFee = document.getElementById('franchiseFee');
    // console.log(franchiseFee.value);
    return parseFloat(franchiseFee.value);
}
export {getFranchiseFee};

main.js file:

import {getFranchiseFee} from './GetElement.mjs';

console.log(getFranchiseFee());

I tried to display the entered value on the console log using a function in the module and print it using the console log in the main.js file.

Now displays an error message telling you that this is not possible

P粉818088880P粉818088880180 days ago379

reply all(1)I'll reply

  • P粉029327711

    P粉0293277112024-04-04 00:45:23

    I copied the wrong export here but it is correct now. This is not a problem

    reply
    0
  • Cancelreply