admin管理员组文章数量:1326511
I am trying to add a drop down bo box with a drop down mega menu.This is my code
if (trendsmega!="")
{
var panymegaid=document.getElementById("megamenu-mlid-783");
//alert("Found "+trendmegaid.innerHTML);
if (panymegaid!="")
{
var otherpaniesli=document.getElementById("megamenu-mlid-1185");
alert(otherpaniesli.innerHTML);
otherpaniesli.innerHTML="";
otherpaniesli.innerHTML= "<select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>";
}
}
I am getting the following error
missing ; before statement
[Break On This Error]
....innerHTML= "<select> <option value="volvo">Volvo</option> <option value="saab"...
/drupal/ (line 1329, col 56)
Can anyone help me how to add a bo box with innerhtml using java script.
I am trying to add a drop down bo box with a drop down mega menu.This is my code
if (trendsmega!="")
{
var panymegaid=document.getElementById("megamenu-mlid-783");
//alert("Found "+trendmegaid.innerHTML);
if (panymegaid!="")
{
var otherpaniesli=document.getElementById("megamenu-mlid-1185");
alert(otherpaniesli.innerHTML);
otherpaniesli.innerHTML="";
otherpaniesli.innerHTML= "<select> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="mercedes">Mercedes</option> <option value="audi">Audi</option> </select>";
}
}
I am getting the following error
missing ; before statement
[Break On This Error]
....innerHTML= "<select> <option value="volvo">Volvo</option> <option value="saab"...
/drupal/ (line 1329, col 56)
Can anyone help me how to add a bo box with innerhtml using java script.
Share Improve this question asked Feb 27, 2012 at 7:30 bharathibharathi 6,27124 gold badges96 silver badges161 bronze badges 1- Dont forget to mark answer as accpeted if you got the info you want – Pranay Rana Commented Feb 27, 2012 at 9:57
3 Answers
Reset to default 6Make use of '
instead of "
in you code.. will remove error.
you code will be
otherpaniesli.innerHTML= "<select> <option value='volvo'>Volvo</option> <option value='saab'>Saab</option> <option value='mercedes'>Mercedes</option> <option value='audi'>Audi</option> </select>";
Whenever you are using string inside a string, use '' sign.
"<select> <option value='volvo'>Volvo</option>";
Or if you have dynamic values use
"<option value="+ saab +">Saab</option>"
You can either do it like this:
otherpaniesli.innerHTML="<select><option value='Volvo'></option></select>"
OR
otherpaniesli.innerHTML='<select><option value="Volvo"></option></select>'
本文标签: Add a drop down combo box into innerHTML using javascript and HTMLStack Overflow
版权声明:本文标题:Add a drop down combo box into innerHTML using javascript and HTML - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742200830a2431928.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论