javascript - can't understand why i receive uncaught reference error function -


i'm trying launch javascript function php initialize module. here code:

<?php defined('_jexec') or die('direct access location not allowed.'); $paramarray[]='advisualv2jmodphp_ver'; $paramarray[]='0.3.0070'; // 000 $paramarray[]='station_id'; $paramarray[]=$params->get('station_id'); // 001 $paramarray[]='verbose'; $paramarray[]=$params->get('verbose'); // 002 $paramarray[]='bk_colorodd'; $paramarray[]=$params->get('bk_colorodd'); // 003 $paramarray[]='bk_coloreven'; $paramarray[]=$params->get('bk_coloreven'); // 004 $paramarray[]='ink_colorodd'; $paramarray[]=$params->get('ink_colorodd'); // 005 echo 'avviamo la procedura 0.0.095 - '.$station_id.'<br><br>'; echo '<div id="tabellaeventi"></div>'; $paramarray = json_encode($paramarray); $paramarray = htmlentities($paramarray); echo "<script language='javascript'>displaytable(0,15)</script>"; echo '<input type="button" value="avanti" onclick="avanti('.$paramarray.')"> '; echo '<input type="button" value="indietro" onclick="indietro('.$paramarray.')"> '; echo '<br>'; ?>  <script> start = 0 page = 15 // displaytable(start,page)  function avanti(listaparametri) {     start=start+page+1     displaytable(start,page) }  function indietro(listaparametri) {     start=start-page-1     if (start<0) {         start = 0     }     displaytable(start,page) }  function displaytable(inizio,incremento) {     xmlhttp=new xmlhttprequest();     xmlhttp.onreadystatechange=function()         {         if (xmlhttp.readystate==4 && xmlhttp.status==200)             {             esito=xmlhttp.responsetext;             }         }     xmlhttp.open('get','xxxxxxxxxxxxxxxx/name.php?start='+inizio+'&page='+incremento,false);     xmlhttp.send();     esito='visualizzazione tabella<br>'+esito+'<br><br>'     document.getelementbyid('tabellaeventi').innerhtml=esito; } </script> 

i continue receive uncaught reference error displaytable not defined in console when page loaded , have call displaytable javascript function, while works if remove // in script javascript section. of course i'm missing , can't understand what, thank (i'm php/javascript beginner, apologize)

as says, displaytable not defined when call it. declare function before calling it. can call function before declared, in case, calling different script tag (enerated in php).

will not work :

<script type="text/javascript"> test(); </script> <script type="text/javascript"> function test() { } </script> 

will work :

<script type="text/javascript"> test(); function test() { } </script> 

and :

<script type="text/javascript"></script> 

is how write script tag.

you must consistent when write code, find mistakes, , less mistakes too.

if use :

bla bla {  } 

don't use

bla bla     {      } 

somewhere else.

don't forget semicolons ; after instructions. keep clear identation, etc.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -