I am trying to add a drop down combo box with a drop down mega menu.This is my code
if (trendsmega!="")
{
var companymegaid=document.getElementById("megamenu-mlid-783");
//alert("Found "+trendmegaid.innerHTML);
if (companymegaid!="")
{
var othercompaniesli=document.getElementById("megamenu-mlid-1185");
alert(othercompaniesli.innerHTML);
othercompaniesli.innerHTML="";
othercompaniesli.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 combo box with innerhtml using java script.
Make use of '
instead of "
in you code.. will remove error.
you code will be
othercompaniesli.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:
othercompaniesli.innerHTML="<select><option value='Volvo'></option></select>"
OR
othercompaniesli.innerHTML='<select><option value="Volvo"></option></select>'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.