gpt4 book ai didi

php - 为什么这个 Javascript 函数不起作用?

转载 作者:行者123 更新时间:2023-11-28 16:38:26 24 4
gpt4 key购买 nike

我使用以下 JavaScript 函数,

function get_check_value(formId,checkboxId,TxtboxId)
{
alert(formId);

var c_value = "";
for (var i=0; i < document.formId.checkboxId.length; i++)
{
if (document.formId.checkboxId[i].checked)
{
c_value = c_value + document.formId.checkboxId[i].value + "\n";
}
}
alert(c_value);
document.getElementById(TxtboxId).value= c_value;
// alert(c_value.value);

}

我的 php 页面有这个,

<form name="orderform" id="orderform">
<input type="text" name="chId" id="chId" >
<table align="center" border="0">
<tr>
<td>Country</td>
</tr>
<? foreach($country as $row){ ?>
<tr>
<td><?= $row['dbCountry']; ?></td>
<td><input type="checkbox" name="CountrycheckId" id="CountrycheckId" value="<?= $row['dbCountryId']; ?> " onClick="get_check_value('orderform','CountrycheckId','chId')"></td>
<? } ?>
</tr>
</table>
</form>

我在 javascript 函数内的警报中收到了 formname、checkboxid、textid...但是问题出在线路上 for (var i=0; i < document.formId.checkboxId.length; i++)

Web开发人员工具栏显示此错误

document.formId is undefined

最佳答案

var selects = document.getElementsByName('CountrycheckId');
for (var i=0; i < selects.length; i++)
{
if (selects[i].checked)
{
c_value = c_value + selects[i].value + "\n";
}
}

关于php - 为什么这个 Javascript 函数不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2497691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com