Question

I have made a combobox using javascript that takes values from the html file itself, below is the code for the combobox:

   <!DOCTYPE html>
   <html lang="en">
   <head>
   <meta charset="utf-8">
   <title>pro-v0</title>
   <style type="text/css" media="screen">
div.combobox    {font-family: Tahoma;font-size: 12px}
div.combobox    {position: relative;zoom: 1}
div.combobox    div.dropdownlist    {display: none;width: 200px;
    border: solid 1px #000;background-color: #fff;
    height: 200px;overflow: auto;position: absolute;
    top: 18px;left: 0px;}
div.combobox    .dropdownlist   a   {display: block;text-decoration: none;
    color: #000;padding: 1px;height: 1em;cursor: default}
div.combobox    .dropdownlist   a.light {color: #fff;
    background-color: #007}
div.combobox    .dropdownlist, input {font-family: Tahoma;font-size: 12px;}
div.combobox    input {float: left;width: 182px;
    border: solid 1px #ccc;height: 15px}
div.combobox    span    {border: solid 1px #ccc;background: #eee;
    width: 16px;height: 17px;
    float: left;text-align: center;border-left: none;cursor: default}
  </style>
  </head>

  <body>
  <div class="combobox">
<input type="text" name="comboboxfieldname" id="cb_identifier">

<span>V</span>
<div class="dropdownlist">
    <a>option 1</a>
    <a>option 2</a>
    <a>option 3</a>
            <a>option 4</a>
</div>
    </div>
    <script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
    <script type="text/javascript" charset="utf-8">
    var no = new inputSelect('cb_identifier');
    </script>
    </body>
    </html>

Now, how to take the values from javascript file or other files or how to create the

dropdownlist div with all the values using javascript. Thanks in advance.

Était-ce utile?

La solution

Try this

...
above same  as your code 

<script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script type="text/javascript" charset="utf-8">
    var no;
    $(document).ready(function(){
      var list = "<a>option 4</a><a>option 4</a><a>option 5</a><a>option 6</a>"
     $(".dropdownlist").append(list).each(function() {
         no = new inputSelect('cb_identifier');
       });
    });

</script>
</body>
</html>

In pure java-script

try using this

<script type="text/javascript" charset="utf-8"    src="https://raw.github.com/RUPOJS/jsCombo/master/combobox.js"></script>
<script type="text/javascript" charset="utf-8">
    var string = "<a>option 5</a><a>option 6</a><a>option 7</a><a>option 8</a>";
    var getElement = document.getElementsByClassName("dropdownlist")[0];
    getElement.innerHTML = getElement.innerHTML+string;
    var no = new inputSelect('cb_identifier');

</script>
</body>
</html>

Use this for looping

<script type="text/javascript" charset="utf-8">
     var strArray = [["option 1"], ["option 2"], ["option 3"], ["option 4"], ["option 4"]]; 
     var string = ""
     for(i=0; i < strArray.length; i++)
     {
        string +="<a>"+strArray[i][0]+"</a>";
     }
     var getElement = document.getElementsByClassName("dropdownlist")[0];
     getElement.innerHTML = getElement.innerHTML+string;
     var no = new inputSelect('cb_identifier');
</script>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top