Javascript document.getElementById(";elementname";).innerHTML=selectText将每个选项值放入我的页面
因此,我使用以下代码:Javascript document.getElementById(";elementname";).innerHTML=selectText将每个选项值放入我的页面,javascript,Javascript,因此,我使用以下代码: function updateSelect(a) { $type = a; if (window.XMLHttpRequest) { xmlhttp=new XMLHttpRequest(); } else { xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP"); } xmlhttp.open("GET","selectbox.php
function updateSelect(a) {
$type = a;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest(); }
else {
xmlhttp=new ActiveXObject
("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","selectbox.php?type=".$type,false);
xmlhttp.send();
selectText=xmlhttp.responseText;
document.getElementById("cultpicklist").options.length=0;
document.getElementById("cultpicklist").innerHTML = selectText;
出于某种原因,它给了我整个页面上的每个选项值(我有几个不同的选择框)!selectText只从数据库的一小部分中提取数据(即,与数据来源完全不同的表)-为什么要这样做
下面是在selectbox.php上生成的内容:
<?php
include "mysql_config.php";
$con = mysql_connect($host, $user, $pass);
if (!$con)
{
die('Could not connect to the database, please contact administrator');
}
mysql_select_db($db);
while ($cultrow = mysql_fetch_array($rescult)) {
ECHO '<option name="culture[]" value="'. stripslashes($cultrow['cult_id']) .'">'. stripslashes($cultrow['cult_desc']) .'</option>';
}
?>
什么是选择文本
?请再输入一些代码。你是说你没有从数据库中获得正确数量的结果吗?如果是这样,那么这是SQL问题,而不是JS问题。selectText
的值是多少?在你的问题中发布它。不,我是说我的页面上有几个选择框,它们的所有值都被转储到了!注意,它们在不同的桌子上。