Retrieving results with PHP and using Javascript

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
the9ulaire
Forum Commoner
Posts: 74
Joined: Mon Jun 11, 2007 11:31 am

Retrieving results with PHP and using Javascript

Post by the9ulaire »

Here is an example of what I want: http://maxandmaxspanish.com/activity/

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>
 
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Retrieving results with PHP and using Javascript

Post by califdon »

Use AJAX. The web is full of tutorials on AJAX. Start with http://w3schools.com/ajax/default.asp
Post Reply