admin管理员组文章数量:1387422
i wrote following code to have a select list on my page:
<select id='defchtype' class='selectpicker form-control' style='width:80%;'>
<option id='Pie' onClick='changechart(".$_GET['id'].",\"Pie\")'>Pie</option>
<option id='Line' onClick='changechart(".$_GET['id'].",\"Line\")'>Line</option>
<option id='Bar' onClick='changechart(".$_GET['id'].",\"Bar\")'>Bar</option>
<option id='Odometer' onClick='changechart(".$_GET['id'].",\"Odometer\")'>Odometer</option>
<option id='Radar' onClick='changechart(".$_GET['id'].",\"Radar\")'>Radar</option>
</select>
this is correctly work when i use mozilla firefox browser. but when i use google chrome browser the onclick event(changechart function) doesn't execute. how can i solve it? thanks this is part of my rendered html code:
<select id='defchtype' class='selectpicker form-control' style='width:80%;'>
<option id='Pie' onClick='changechart(126,"Pie")'>Pie</option>
<option id='Line' onClick='changechart(126,"Line")'>Line</option>
<option id='Bar' onClick='changechart(126,"Bar")'>Bar</option>
<option id='Odometer' onClick='changechart(126,"Odometer")'>Odometer</option>
<option id='Radar' onClick='changechart(126,"Radar")'>Radar</option>
</select>
and this is my javascript function:
function changechart(id,chtype){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//response="server/img/useravatars/"+xmlhttp.responseText;
response=xmlhttp.responseText;
document.getElementById("chartcontainer").innerHTML=response;
document.getElementById(chtype).selected="true";
}
}
var req="showchart.php?id="+id+"&chtype="+chtype;
xmlhttp.open("GET",req,true);
xmlhttp.send();
}
the javascript function even doesn't execute in chrome. but in firefox work's correctly
i wrote following code to have a select list on my page:
<select id='defchtype' class='selectpicker form-control' style='width:80%;'>
<option id='Pie' onClick='changechart(".$_GET['id'].",\"Pie\")'>Pie</option>
<option id='Line' onClick='changechart(".$_GET['id'].",\"Line\")'>Line</option>
<option id='Bar' onClick='changechart(".$_GET['id'].",\"Bar\")'>Bar</option>
<option id='Odometer' onClick='changechart(".$_GET['id'].",\"Odometer\")'>Odometer</option>
<option id='Radar' onClick='changechart(".$_GET['id'].",\"Radar\")'>Radar</option>
</select>
this is correctly work when i use mozilla firefox browser. but when i use google chrome browser the onclick event(changechart function) doesn't execute. how can i solve it? thanks this is part of my rendered html code:
<select id='defchtype' class='selectpicker form-control' style='width:80%;'>
<option id='Pie' onClick='changechart(126,"Pie")'>Pie</option>
<option id='Line' onClick='changechart(126,"Line")'>Line</option>
<option id='Bar' onClick='changechart(126,"Bar")'>Bar</option>
<option id='Odometer' onClick='changechart(126,"Odometer")'>Odometer</option>
<option id='Radar' onClick='changechart(126,"Radar")'>Radar</option>
</select>
and this is my javascript function:
function changechart(id,chtype){
var xmlhttp;
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
//response="server/img/useravatars/"+xmlhttp.responseText;
response=xmlhttp.responseText;
document.getElementById("chartcontainer").innerHTML=response;
document.getElementById(chtype).selected="true";
}
}
var req="showchart.php?id="+id+"&chtype="+chtype;
xmlhttp.open("GET",req,true);
xmlhttp.send();
}
the javascript function even doesn't execute in chrome. but in firefox work's correctly
Share Improve this question edited Mar 15, 2015 at 1:59 Sirwan Rauofi asked Mar 15, 2015 at 1:47 Sirwan RauofiSirwan Rauofi 1521 gold badge3 silver badges14 bronze badges 3- 2 Can you post the rest of the changeChart code? – Miguel Commented Mar 15, 2015 at 1:48
- You need to post a plete code example, which in this case includes the JavaScript and the rendered HTML (not the PHP). – j08691 Commented Mar 15, 2015 at 1:50
- 2 You should be using the onchange event of the select, not the onclick of the options. See stackoverflow./questions/9972280/… – j08691 Commented Mar 15, 2015 at 2:01
1 Answer
Reset to default 4You should not use the onClick
Event within option
Elements. Use the onchange
event of the select instead as already discussed in this question: javascript onclick alert not working in chrome .
本文标签: javascriptOnClick event doesn39t work in ChromeStack Overflow
版权声明:本文标题:javascript - OnClick event doesn't work in Chrome - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744493032a2608850.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论