Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am making an application,in which i am making combobox(ie dropdownlist) dynamically by javascript
I have a div on my page and appending the generated combobox on that div
The code is working fine as of the required functionality in IE and chrome,but when i checked it on FireFox,it is not making any dropdown,i checked it on console of Firebug it is showing the error that div is not defined can any one help???


C#
var numi = document.getElementById('theValue');
var ni=document.getElementById('mydiv');
        var num = (document.getElementById('theValue').value - 1) + 2;
        divname = ni;
        numi.value = num;
        var newdiv = document.createElement('div');

        var divIdName = 'my' + num + 'Div';
        //Calculating Major and Minor Count
        var majorcount = parseInt(document.getElementById('majorcount').value);
        newdiv.setAttribute('id', divIdName);
        if (ni.id == "addmajordiv") {
            var select = document.createElement('select');      
select.setAttribute("name", document.getElementsByTagName('select')[j].name);
                select.setAttribute("style", "width: 350px;height:35px;");
            var link=document.createElement('a');
            link.setAttribute('onclick', 'removeElement(' + divIdName + ')');
            link.setAttribute('style', 'font-size: 120%;font-weight: bold');
            link.setAttribute('href', '#');
            link.innerText = "Remove";
      

            for (var i = 0; i < document.getElementById('all').length; i++) {
                var option = document.createElement("option");
                option.text = document.getElementById('all')[i].text;
                option.value = document.getElementById('all')[i].value;
                try {
                    select.add(option, null); //Standard
                    select.id = "MajorCourse";
                    select.name = "MajorCourse";
                } catch (error) {
                    select.add(option); // IE only
                }
            }
            newdiv.appendChild(select);
            newdiv.appendChild(link);           
            majorcount = majorcount + 1;
            document.getElementById('majorcount').value = majorcount;
        }
Posted
Updated 13-Jan-12 0:45am
v2
Comments
Kethu Sasikanth 13-Jan-12 14:02pm    
It is hard to tell where the problem is. I donot think "div" is problem, script was failing somewhere in the middle. But my suggestion is while testing on FirFox, comment out lines from - "var link=.." to "}}" before newdiv.appendChild(select). Run the app and see for the results. If it is successful then uncomment one line or multiple related lines at a time then run and see which line is giving the problem.
Can you just post the design codes, so that I can make out what the problem.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900