我正忙于一个可以创建发票的脚本。我在 StackOverflow 上找到了一个脚本,可以通过下拉菜单填写表格。
<?
$sPrijzen = mysql_query("SELECT * FROM prices WHERE company='".$CID."' ")or die(mysql_Error());
?>
<script type="text/javascript">
var omschrijving = new Array();
var ppe = new Array();
var btw = new Array();
var btw_percentage = new Array();
omschrijving[0] = "";
ppe[0] = "";
btw[0] = "";
btw_percentage[0] = "";
<?
$i = 1;
while($fPrijzen = mysql_fetch_assoc($sPrijzen))
{
?>
omschrijving[<?=$i;?>] = "<?=$fPrijzen['omschrijving'];?>"
ppe[<?=$i;?>] = "<?=$fPrijzen['ppe'];?>"
btw[<?=$i;?>] = "<?=$fPrijzen['btw'];?>"
btw_percentage[<?=$i;?>] = "<?=$fPrijzen['ppe'];?>"
<?
$i++;
}
?>
function Choice1() {
//x = document.getElementById("users");
y = document.getElementById("selectProduct1");
//x.value = y.options[y.selectedIndex].text;
document.getElementById("omschrijving").value = omschrijving[y.selectedIndex];
document.getElementById("ppe").value = ppe[y.selectedIndex];
document.getElementById("btw").value = btw[y.selectedIndex];
document.getElementById("btw_percentage").value = btw_percentage[y.selectedIndex];
}
</script>
我的 HTML 看起来像这样:
<select id="selectProduct1" name="users" onChange='Choice1();'><option></option>
<option value="1">Product 1</option>
<option value="2">Product 2</option>
<option value="3">Product 3</option>
</select>
<p>ids <input type="text" id="omschrijving" name="id" ></p>
<p>use <input type="text" id="ppe" name="username" ></p>
<p>ful <input type="text" id="btw" name="full_name" ></p>
<input type="checkbox" name="1-zesprocent" value="ja" <? if?> /> 6%
<input type="checkbox" name="1-nulprocent" value="ja" /> 0%
一切正常。文本输入的值将被自动填充。但是现在我有 2 个带有我国增值税的复选框(6% 和 0%)。我想在通过下拉列表选择它时自动“检查”它。有人可以帮我解决这个问题吗?