小故障,但可能是一个重要问题
Small glitch but could be an important issue
我目前有一个问题,我的下拉菜单使用JavaScript/AJAX和PHP。
下面是edit.php文件的代码,该文件应该从下拉列表中的多个选择框中检索数据:
<td ><input readonly type="text" id="mainlines" value='<?php echo $_SESSION["mainlines"];?>' name="mainlines"/> </td>
<td ><input readonly type="text" id="categories" value='<?php echo $_SESSION["categories"]; ?>' name="categories"/> </td>
<td>
<select name="subcategories" id="menu" onChange="SelectAccountHead_Code(this.value)">
<option value="<?php print $subcategories; ?>"><?php print $subcategories; ?></option>
<?php
$sql1a = "SELECT * FROM subcategory ORDER BY subcategories asc";
$smt1a = $dbs->prepare($sql1a);
$smt1a -> execute();
while($row1a=$smt1a->fetch(PDO::FETCH_ASSOC))
{
if($row1a['subcategories']==$_GET['id2'] )
echo ("<option selected value=$row1a[subcategories]>$row1a[subcategories]</option>");
else
echo ("<option value=$row1a[subcategories]>$row1a[subcategories]</option>");
}
?>
</select>
</td>
对于"mainlines"answers"categories",我只在被选中时才得到显示输出的数据,但是当项目被编辑时,它不会自动打印出来,除非我使用"print $mainlines"或"print $categories"。
如何在if/else语句中插入onChange
事件更改器?
我希望它在伪代码中声明以下内容:
if (onChange = "SelectAccountHead_Code(this.value)"){
print $mainlines;
} else {
echo $_SESSION["mainlines"];
}
如何在if/else子句中插入关于JavaScript/AJAX事件更改器/处理程序的正确语法?
更新:这是我的JavaScript代码-我在哪里错过了AJAX代码?
function SelectAccountHead_Code(i)
{
var k=document.getElementById("menu").selectedIndex;
var l=document.getElementById("menu1").selectedIndex;
if((k>0)&&(l>0))
{
self.location="edit3.php?productsnames=<?php print $productsnames;?>&id="+document.getElementById("menu").options[k].value+"&id2="+document.getElementById("menu").options[k].innerHTML +"&id3="+document.getElementById("menu1").options[l].value+"&id3="+document.getElementById("menu1").options[l].innerHTML;
}
}
function SelectAccountHead_Codes(j)
{
var k=document.getElementById("menu").selectedIndex;
var l=document.getElementById("menu1").selectedIndex;
if((k>0)&&(l>0))
{
self.location="edit3.php?productsnames=<?php print $productsnames;?>&id="+document.getElementById("menu").options[k].value+"&id2="+document.getElementById("menu").options[k].innerHTML +"&id3="+document.getElementById("menu1").options[l].value+"&id3="+document.getElementById("menu1").options[l].innerHTML;
}
}
function SelectUp(i)
{
var k=document.getElementById("menuUp").selectedIndex;
var l=document.getElementById("menuUp").selectedIndex;
self.location="edit3.php?id="+document.getElementById("menuUp").options[k].value+"&id2="+document.getElementById("menu").options[k].innerHTML +"&id3="+document.getElementById("menu1").options[l].value+"&id3="+document.getElementById("menu1").options[l].innerHTML;
}
function SelectUp(j)
{
var k=document.getElementById("menuUp").selectedIndex;
var l=document.getElementById("menuUp").selectedIndex;
self.location="edit3.php?id="+document.getElementById("menuUp").options[k].value+"&id2="+document.getElementById("menu").options[k].innerHTML +"&id3="+document.getElementById("menu1").options[l].value+"&id3="+document.getElementById("menu1").options[l].innerHTML;
}
如果没有进一步的请求(Ajax)和服务器交互,就不能将Javascript和PHP组合在一起。
其他大错误:
echo ("<option selected value=$row1a[subcategories]>$row1a[subca.........
你的关联数组中有constants
看这个例子为什么是错误的:
$array = array('test' => 111);
define('test', 999);
echo $array[test];
正确的:
echo ("<option selected value='" . $row1a['subcategories'] . "'>" . $row1a['su..
// consider adding htmlspecialchars() or addslashes() to your output
更多小错误/坏习惯:
-
onChange
均为小写字母:onchange
if .. else
块应该有{
}
相关文章:
- 火狐中的多个问题,但在 chrome 中工作正常,没有一个问题
- 是否从超时内开始间隔是一个问题
- java脚本我需要帮助来解决一个问题
- Dreaded 100%边栏高度-jQuery修复,但另一个问题出现了
- I'我在用JavaScript进行验证时遇到了一个问题
- Jstree-Can't在AJAX调用中选中复选框,适用于经典调用.一个问题
- 我在角度指令和角度路由中有一个问题
- 我有一个问题,使用 Javascript 或 Jquery 创建具有字符串计数的动态字段
- 如何在测验应用中移动到下一个或上一个问题
- 如何创建按钮转到测验软件中的下一个问题
- 我对用php代码创建的HTML有一个问题
- 我想使用fbi . event .subscribe记录跟踪值在Facebook喜欢按钮,但遇到了一个问题
- 如果效率是一个问题,如何修改JavaScript修剪函数?
- 一个问题与大量的图像-广告画廊插件
- 新的局部变量在大的FOR循环,这是一个问题
- 我在放大分形(webgl)时遇到了一个问题
- jQuery对话框的一个问题
- 在javascript中,通过一个对象数组为每个对象发出一个问题
- 浏览器渲染网页的顺序是什么,为什么脚本阻塞是一个问题
- 闭包编译器外部解决了一个问题,但我不明白为什么