esempio veloce funzionante per il controllo di due funzioni:
codice:
<HTML>
<HEAD>
<TITLE>demo</TITLE>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="Cache-Control" content="no-cache">
<script>
window.onload = function(){
var prezzo = Math.floor(Math.random() * (99))
var spedizione = Math.floor(Math.random() * (99))
document.getElementById('importo').innerHTML=prezzo
document.getElementById('spese').innerHTML=spedizione
}
function f1(){
if(document.getElementById('somma').value != parseInt(document.getElementById('importo').innerHTML)+parseInt(document.getElementById('spese').innerHTML)){
alert("inserisci una somma esatta")
return false;}else{return true;}
}
function f2(){
if(document.getElementById('nome').value==""){
alert('inserisci un nome');
return false;}
else{return true;}
}
</script>
</HEAD>
<BODY>
<form name="myform" action="#" method="POST" onSubmit="return (f1() && f2()) ">
<fieldset>
<legend>Doppio controllo</legend>
<div id="importo"></div><div id="spese"></div>
<input name="somma" id="somma" size="26" value="" />
<input name="nome" type="text" id="nome">
<input type="submit" name="invia" value="Submit!" >
</fieldset>
</form>
</BODY>
</HTML>