admin管理员组

文章数量:1326683

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
Add a ment  | 

3 Answers 3

Reset to default 6

Make 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