Now how would I incorporate my PHP results into my javascript? I am new to javascript and don't know how to efficiently go about this. Here is my code:
Code: Select all
<?php
require("conn.php");
$sql = "SELECT question, answer FROM translations WHERE category=1 LIMIT 25";
$result = mysql_query($sql, $conn) or die("Could not retrieve translations: " . mysql_error());
$rows = mysql_num_rows($result);
while(mysql_fetch_array($result)) {
}
?>
<script>
function openLoad() {
document.myform.question.value = "What does 'Hola' mean?";
document.myform.show.value = "show";
}
function show1() {
if(document.myform.show.value == "show") {
document.myform.answer.value = "Hello.";
document.myform.show.value = "hide";
} else if(document.myform.show.value == "hide") {
document.myform.answer.value = "";
document.myform.show.value = "show";
}
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Untitled Document</title>
<style type="text/css">
<!--
.forms {
margin: 3px;
padding: 3px;
border: solid 1px #000000;
width: 570px;
text-align: center;
}
.question {
border: 0px;
color: #000099;
width: 250px;
text-align: right;
}
.answer {
border: 0px;
color: #990000;
width: 250px;
text-align: left;
}
.button {
width: 45px;
text-align: center;
}
-->
</style></head>
<body onload="openLoad();">
<form name="myform" class="forms">
<input type="text" name="question" readonly class="question" />
<input type="button" name="show" value="" onclick="show1();" class="button" /> =
<input type="text" name="answer" readonly class="answer" />
</form>
</body>
</html>