Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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 如何从Codeigniter中的表单_dropdown()中检索值_Php_Javascript_Codeigniter - Fatal编程技术网

Php 如何从Codeigniter中的表单_dropdown()中检索值

Php 如何从Codeigniter中的表单_dropdown()中检索值,php,javascript,codeigniter,Php,Javascript,Codeigniter,我正在使用codeigniter。我有一个简单的表单下拉列表()。我想为下拉列表执行onchange()函数 我将获得通过JavaScript选择的字符串 这是我的代码,但它不工作 $js ="onChange=message()"; echo "<script type=\"text/javascript\" > function message(){ var no=document.getElementById('name').value; alert(sr); } </

我正在使用codeigniter。我有一个简单的表单下拉列表()。我想为下拉列表执行onchange()函数

我将获得通过JavaScript选择的字符串

这是我的代码,但它不工作

$js ="onChange=message()";
echo "<script type=\"text/javascript\" > function message(){ var no=document.getElementById('name').value;

alert(sr);
}
</script>";
echo form_dropdown('name',$data,'large',$js);
$js=“onChange=message()”;
echo“function message(){var no=document.getElementById('name').value;
警报(sr);
}
";
echo form_下拉列表('name',$data,'large',$js);

form\u下拉列表不会自动向元素添加id,因此
getElementById
不会按编写的方式工作

另外,为了理解,指南没有很好地解释第四个参数。将其命名为
$js
会产生误导,因为它会将您赋予它的任何内容添加到属性列表中

将一行代码更改为(注意onChange函数周围的引号):

确保在输出源代码后查看源代码,以验证它是否也输出了有效的html

此外,在Chrome上,F12将打开开发人员工具,按esc键将切换显示JavaScript控制台,如果一切没有按计划进行,这将有望给您带来有意义的错误

编辑:


看起来您正在设置一个名为
no
的变量的值,但向一个名为
sr
的变量发出警报,该变量似乎没有定义

您也可以简单地从函数调用中传递ref,这将很容易,而不是从
文档中获取值。getElementById()
,当您在select dropdowm中添加id时,它将起作用

试试这个代码

<?php 
echo "<script type=\"text/javascript\" > 
        function message(element){ 
           var no=element.value;
           alert(no);
         }
</script>";

echo form_dropdown('name',$data,'large', 'onChange="message(this);"'); 

?>

这是在调用它的onchange函数,我们必须以表单_dropdown()作为第四个参数传递它。控制台的javascript错误是什么?很抱歉,我不知道如何在浏览器中获取javascript的控制台。现在我正在使用google chrome..@user1594794,然后从@sandip message()添加一个是一个javascript函数,在“this。。
<?php 
echo "<script type=\"text/javascript\" > 
        function message(element){ 
           var no=element.value;
           alert(no);
         }
</script>";

echo form_dropdown('name',$data,'large', 'onChange="message(this);"'); 

?>