Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/404.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 为什么这个Javascript函数没有';不行?_Php_Javascript - Fatal编程技术网

Php 为什么这个Javascript函数没有';不行?

Php 为什么这个Javascript函数没有';不行?,php,javascript,Php,Javascript,我使用以下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

我使用以下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);
函数获取检查值(formId、checkboxId、TxtboxId)
{
警报(formId);
var c_值=”;
对于(var i=0;i
}

我的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>

国家

您需要通过getElementById(formId)访问表单,请参见以下内容:

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

     var c_value = "";
     for (var i=0; i < document.getElementById(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);
  }
函数获取检查值(formId、checkboxId、TxtboxId)
{
警报(formId);
var c_值=”;
for(var i=0;i

当您编写文档时。formId Javascript将在您使用文档时查找名称为(字面意思是)“formId”的文档属性。getElementById(formId)Javascript将查找id为变量formId所包含的任何内容的HTML元素。

您需要通过getElementById(formId)访问表单,请参见以下内容:

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

     var c_value = "";
     for (var i=0; i < document.getElementById(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);
  }
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";
   }
}
函数获取检查值(formId、checkboxId、TxtboxId)
{
警报(formId);
var c_值=”;
for(var i=0;i
当您编写document.formId时,当您使用document时,Javascript将查找名称为(字面意思为)“formId”的document属性。getElementById(formId)Javascript将查找id为变量formId所包含的任何内容的HTML元素。

var selects=document.getElementsByName('CountrycheckId');
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";
   }
}
对于(变量i=0;i
var selects=document.getElementsByName('CountrycheckId');
对于(变量i=0;i
我认为文档中有多个id相同的元素。这是无效的。ID是唯一的,不能分配给多个元素。您可以为此使用名称,并使用

document.getElementsByName("name");

var checkBoxes = document.getElementsByName('CountrycheckId');
var c_value = new Array();

for (var i=0; i < checkBoxes.length; i++)
{
   if (checkBoxes[i].checked)
   {
       c_value.push(checkBoxes[i].value);
   }
}

// join the array using any delimiter like

c_value.join(',');

我认为文档中有多个具有相同id的元素。这是无效的。ID是唯一的,不能分配给多个元素。您可以为此使用名称,并使用

document.getElementsByName("name");

var checkBoxes = document.getElementsByName('CountrycheckId');
var c_value = new Array();

for (var i=0; i < checkBoxes.length; i++)
{
   if (checkBoxes[i].checked)
   {
       c_value.push(checkBoxes[i].value);
   }
}

// join the array using any delimiter like

c_value.join(',');

@Itay still same error
document.getElementById(formId)。checkboxId未定义
@Itay still same error
document.getElementById(formId)。checkboxId未定义
@micheal prob这是获取checkboxes@micheal可能这是获取复选框值的最佳方法