简体   繁体   中英

Why am I getting a "function not defined" error when there are 2 functions in the script tag?

The script tag part in <head> :

  function reload()
  {
     //some code


  }
  function bookconfirm(clickinfo)
  {
        //some code
  }

The part that are calling them:

           <select name="city" onchange="reload()">

          <td><button type="button" onclick="bookconfirm(<?php echo $c;?>)">Book</button></td>

Errors:

             Uncaught ReferenceError: reload is not defined at HTMLSelectElement.onchange


        Uncaught ReferenceError: bookconfirm is not defined  at HTMLButtonElement.onclick 

I'm probably unable to understand how functions work in js or something , thanks for your time and knowledge.

seems to work fine. Make sure your html is correct, your select statement needs some fine tuning. also make sure the html appears before the script is called. (ie place the script just before the closing body tag, although in this case you can also keep it in the head tag but remember you can get errors if the javascript tries to execute before the the dom is fully loaded)

 function reload() { console.log('reload'); } function bookconfirm(clickinfo) { console.log(clickinfo); }
 <select name="city" onchange="reload()"> <option></option> <option>test</option> </select> <button type="button" onclick="bookconfirm('bookconfirm')">Book</button>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM