【发布时间】:2010-07-01 22:33:59
【问题描述】:
我用的是phpBMS,做了一个表格,类似于sample provided。
使用提供的输入字段,我制作了一个包含两个项目和一个复选框的基本下拉列表。
我希望在选择下拉框中的选项之一时自动选中复选框。
Jens F,为我提供了如何在 javascript here 中执行此操作的解决方案。
但是,由于某种原因,我无法执行 javascript。
我在一个名为 checkpaid.js 的文件中有 javascript,该文件包含在我的表单中。使用 firebug 我可以看到 javscript 文件已被提取,并出现在脚本列表中,但它绝对从未执行过。
当它明确包含在页面中时,我如何开始弄清楚它为什么不执行?
Here 是为现有表单提供的 javascript 示例,如果单击单选按钮,它将执行操作。
这是我当前的表单和 javascript:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
include("../../include/session.php");
include("include/tables.php");
include("include/fields.php");
include("include/sales.php");
if(!isset($_GET["backurl"]))
$backurl = NULL;
else{
$backurl = $_GET["backurl"];
if(isset($_GET["refid"]))
$backurl .= "?refid=".$_GET["refid"];
}
$thetable = new sales($db, "tbld:490cf2d1-1c72-7b99-461d-b1b8e68553c4");
$therecord = $thetable->processAddEditPage();
if(isset($therecord["phpbmsStatus"]))
$statusmessage = $therecord["phpbmsStatus"];
$pageTitle = "Sales";
$phpbms->cssIncludes[] = "pages/menus.css";
$phpbms->jsIncludes[] = "modules/base/javascript/menu.js";
$phpbms->jsIncludes[] = "modules/micro hospitality/javascript/checkpaid.js";
$phpbms->onload[] = "initializePage()";
$theform = new phpbmsForm();
$theinput = new inputSmartSearch($db, "chooseguests", "Choose Guests",NULL, "Choose Guest", TRUE, NULL, NULL, TRUE, $required=true);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$theinput = new inputSmartSearch($db, "chooseproducts", "Choose Product",NULL, "Choose Product", TRUE, NULL, NULL, TRUE, $required=true);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$theinput = new inputField("quantity",$therecord["quantity"],"Quantity",true, NULL, 1);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$theinput = new inputBasicList("type",$therecord["paymenttype"],array("Cash"=>"cash","Credit"=>"credit"), "Payment Type");
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$theinput = new inputCheckbox("paid", $therecord["paid"], "Paid");
$theform->addField($theinput);
$theinput = new inputField("receiptno",$therecord["receiptno"],"Receipt No",true, NULL, 10);
$theinput->setAttribute("class","important");
$theform->addField($theinput);
$thetable->getCustomFieldInfo();
$theform->prepCustomFields($db, $thetable->customFieldsQueryResult, $therecord);
$theform->jsMerge();
include("header.php");
?><div class="bodyline">
<?php $theform->startForm($pageTitle)?>
<div id="leftSideDiv">
<fieldset>
<legend><label for="S">Sales</label></legend>
<p class="big"><?php $theform->showField("chooseguests"); ?></p>
<p class="big"><?php $theform->showField("chooseproducts"); ?></p>
<p class="big"><?php $theform->showField("quantity"); ?></p>
<p class="big"><?php $theform->showField("type"); ?></p>
<p class="big"><?php $theform->showField("paid"); ?></p>
<p class="big"><?php $theform->showField("receiptno"); ?></p>
</fieldset>
</div>
<?php
$theform->showGeneralInfo($phpbms,$therecord);
$theform->endForm();
?>
</div>
<?php include("footer.php");?>
------------------
checkpaid.js:
window.addEvent('domready', function(){
$('type').addEvent('change',function(){
if($(this).get('value') == 'credit') {
$('paid').set('checked','checked');
} else {
$('paid').removeProperty('checked');
}
});
});
alert("loaded");
【问题讨论】:
-
您使用的是什么 JavaScript 库? IE。是什么提供了 domready 事件挂钩?
-
phpBMS 使用 mootools,这就是它的本意。它确实可以在 phpbms 之外正常工作。
-
确保下拉列表的ID实际上是“类型”,您可以在更改事件中放置警报语句或“console.log(“已执行”)以查看该段代码是否实际上正在执行。如果不是 - 发布页面的 url,以便我可以进一步调查。
-
我无法让您访问我的页面..我愿意,但我在 NAT 之后并且无权更改它。正如您在我的表单中看到的那样,ID 是明确的类型,并且在输出 HTML 中得到确认。我同时放了一个警报和console.log(“已执行”),它似乎根本没有执行......但我不知道为什么?
-
检查控制台是否有错误。另外,验证 mootools 库确实正在加载。
标签: php javascript ajax forms phpbms