我的测试代码如下:两个文件都是 .php 以避免冲突,我已经编程了 30 年,但是对 .js 和 .php 还是陌生的,我不知道应该是什么语法很容易. 我已阅读并尝试了所有适用的示例,但它们对我没有用。请告诉我我在哪里搞砸了!!
<!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>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>TestofTopicText</title>
<script language="Javascript">
<!--
function OnButton1()
{
var newtopic = document.getElementById('topic');
document.Form1.target = "_self";
document.Form1.action = "1-open-close.php?var=$newtopic";
document.Form1.submit(); // Submit the page
}
-->
</script>
</head>
<body>
<h3><span style="color: #00ff00;">If NOT found to right ENTER Your Topic Here! </span></h3>
// Using get method as I read was appropriate for getElementById
<form id="Form1" method="get" name="Form1">
<input type="text" name="q" id="topic" size="55" />
<input type="submit" name="sa" value="Search" onclick="OnButton1()"/>
</form>
</body>
</html>
// I am passing to this .php file known as 1-open-close.php
// The file opens and writes test text but I can't get topic text from other file?
<?php
$topic = $_GET['var'];
$myFile = "Topics.txt";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "Test to Make Sure Open \n";
fwrite($fh, $topic);
fwrite($fh, $stringData);
fclose($fh);
// return true;
?>