0

我刚刚进入 PHP、Javascript 和 HTML 的世界,并希望社区提供有关以下代码的一些帮助。基本上,我想将 PHP 从 ODBC_connection 中提取的变量传递到文本框中。第 1-3 行是让我测试让框更新它所做的,但 PHP 回显的任何内容都不会运行。我对此完全陌生,所以我意识到我一定遗漏了一些微不足道的东西。

我欢迎任何关于我可以做些什么来解决这个问题或我可以做得更好的建议或意见。谢谢你。

<script type='text/javascript'>
document.getElementById('modeltxt').value = "test2";
</script>
<?php
echo "<script type='text/javascript'>";
echo "document.getElementById('modeltxt').value =\"TEST3\";";  
echo "document.getElementById('customertxt').value = $customer;";  
echo "document.getElementById('endusertxt').value = $enduser;";  
echo "document.getElementById(dongletxt').value = $dongle;";
echo "document.getElementById('shipdatetxt').value = $shipdate;";
echo "document.getElementById('chasistypetxt').value = $chasistype;";
echo "document.getElementById('chasisnumbertxt').value = $chasisnumber;";  
echo "document.getElementById('opsystxt').value = $opsys;";
echo "document.getElementById('dvd1txt').value = $dvd1;";  
echo "document.getElementById('dvd2txt').value = $dvd2;";
echo "document.getElementById('storagetxt').value = $storage;";  
echo "document.getElementById('nodrivetxt').value = $nodrive;";
echo "document.getElementById('drivesizetxt').value = $drivesize;";  
echo "document.getElementById('interface1txt').value = $interface1;";  
echo "document.getElementById('interface2txt').value = $interface2;";  
echo "document.getElementById('interface3txt').value = $interface3;";  
echo "document.getElementById('interface4txt').value = $interface4;";  
echo "document.getElementById('interface5txt').value = $interface5;";  
echo "document.getElementById('interface6txt').value = $interface6;";  
echo "document.getElementById('commentstxt').value = $comments;";
echo "document.getElementById('warrantyexptxt').value = $warrantyexp;";
echo "document.getElementById('extendedwarrantytxt').value = $extwarexp;";  
echo "document.getElementById('onsitetxt').value = $onsite;";
echo "document.getElementById('sqlversiontxt').value = $sqlversion;"; 
echo "<\script>";
4

2 回答 2

2

您可以使用以下创建动态 JS

Define Content-Type on the top of your .js.php file:
<?
header('Content-Type: application/javascript');
// Write your php code
?>
 and call the js file like this ..

<script type="application/javascript" src="JS_PATH/name-of-file.js.php"></script>

如果你想使用内联 php 值,你可以这样写

<script type="application/javascript">
document.getElementById('modeltxt').value = "<?php echo $dummy_value ?>";
</script>
于 2013-11-15T06:51:36.790 回答
0

无需这样做。您可以简单地在 php 中使用 javascript,如下所示:-

正如你在问题中提到的

基本上,我想将 PHP 从 ODBC_connection 中提取的变量传递到文本框中。

<?php
  // Php block of code

?>
<script type="text/javscript">
  document.getElementById('modeltxt').value = "TEST3";
  document.getElementById('customertxt').value = "<?php echo $customer;?>"; 
   ......
   ....
   ...
</script>
<?php

// Another block of code

?>
于 2013-11-15T06:24:20.127 回答