Function on Javascript. Not work -
i have file .js 1 function. , starting class want call function. not know why, function returns nothing. code have follows:
//valida data inserida pelo utilizador. function validardata(){ var datavalor = window.document.forms[0].data.value; if(datavalor == ''){ //verifica se o campo data está preenchido alert('o campo data encontra-se vazio. seleccione uma data!'); return false; }else{ var t = validar(datavalor); alert(t); return false; } }
the code in file .js is:
function validar(data){ return data; }
does have idea why not work?
without accompanying html go off of, answer shooting in dark.. but, provided attach function submit event, returning value of function...
<form onsubmit="return validardata();"> <!-- ^ - in submit event(just listing way simple explanation instead of advanced event attaching) -->
and provided functions defined in document head, or body, code works fine me:
<form method="post" onsubmit="return validardata()"> <input type="text" name="data" /> <input type="submit" /> </form>
//valida data inserida pelo utilizador. function validardata(){ var datavalor = window.document.forms[0].data.value; console.log(datavalor); if(datavalor == ''){ //verifica se o campo data está preenchido alert('o campo data encontra-se vazio. seleccione uma data!'); return false; }else{ var t = validar(datavalor); alert(t); return false; } } function validar(data){ return data; }
of course, that's assuming correctly link functions if exist in other files..
<script type='text/javascript' src='path/to/script.js'></script>
Comments
Post a Comment