Buongiorno a tutti,
scrivo nel forum perch� non trovo piu dove sbattere la testa..
Il mio problema � l'interfacciare il PHP con l'HTML utilizzando il JavaScript.
Piu nello specifico ho bisogno di inserire in un paragrafo HTML il valore di una variabile PHP, ma solo dopo aver premuto un bottone che, tramite JS faccia partire lo script per il cambio di testo..
Di seguito lascio il codice.. grazie in anticipo.
<html>
<head>
<style type="text/css">
#vero{
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: bold 12px Arial, Helvetica, sans-serif;
color: #fff;
padding: 10px 20px;
border: solid 1px #0076a3;
background: #03C03C;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
background: -webkit-gradient(linear, left top, left bottom, from(#02f940), to(#017a1f));
background: -webkit-linear-gradient(top, #02f940, #017a1f);
background: -moz-linear-gradient(top, #02f940, #017a1f);
background: -ms-linear-gradient(top, #02f940, #017a1f);
background: -o-linear-gradient(top, #02f940, #017a1f);
}
#falso{
outline: none;
cursor: pointer;
text-align: center;
text-decoration: none;
font: bold 12px Arial, Helvetica, sans-serif;
color: #fff;
padding: 10px 20px;
border: solid 1px #0076a3;
background: #D21F1B;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
background: -webkit-gradient(linear, left top, left bottom, from(#f90a02), to(#a50500));
background: -webkit-linear-gradient(top, #f90a02, #a50500);
background: -moz-linear-gradient(top, #f90a02, #a50500);
background: -ms-linear-gradient(top, #f90a02, #a50500);
background: -o-linear-gradient(top, #f90a02, #a50500);
}
#text{
outline: none;
text-align: center;
text-decoration: none;
font: bold 12px Arial, Helvetica, sans-serif;
color: black;
padding: 10px 20px;
border: solid 1px #0076a3;
background: white;
-moz-border-radius: 8px;
-webkit-border-radius: 8px;
border-radius: 8px;
width:700px;
height:125px;
}
</style>
<script>
var count=0;
function quiz(risposta){
var a="<? echo $potato ?>"//testo del quiz
var b="vero"//riposta del quiz
if(risposta!=b){
count++;
}
document.getElementById("text").innerHTML=a //aggiornamento testo del quiz
}
function aggiorna(){
document.getElementById("count").innerHTML="il numero di errori e':"+count; //prova per controllare la var count
}
</script>
</head>
<body bgcolor=#6397D0>
<p id="php">
<?
$cn=mysql_connect("nome_server", "username", "password");
mysql_select_db("nome_db", $cn);
$query=mysql_query("SELECT* FROM quiz", $cn);
$quantita=mysql_num_rows($query);
$potato="prova";
?>
</p>
<center>
<img src="Immagine_da_aggiungere.png">
<p id="text">testo del quiz</p>
<button onclick=quiz("vero") id="vero">vero</button>
<button onclick=quiz("falso") id="falso">falso</button>
<p id="count">il numero di errori e' :0</p>
<button onclick=aggiorna()>aggiorna count </button>
</center>
</body>
</html>