Hi,

I'm playing with javaScript and AJAX and using the source code used in this page: http://www.codeproject.com/KB/webforms/MultiSelectDropDown.aspx (Actually I copied the code on the Default.aspx to the page I was working on, which has a MasterPage and translated Default.aspx.cs from C# to VB.NET)
However, I'm having an "Object Required Error" in the line

divRef.style.display = "block";

Any ideas why is this happening?

Thanks,

Ana

Recommended Answers

divRef probably doesn't exist, show the whole code not just one line.

Jump to Post

All 4 Replies

divRef probably doesn't exist, show the whole code not just one line.

The code was on the link. But here it goes:

<script type="text/javascript">
   var timoutID;

   //This function shows the checkboxlist
   function ShowMList()
   {
       var divRef = document.getElementById("divCheckBoxList");
       [B]divRef.style.display = "block";[/B]
       var divRefC = document.getElementById("divCheckBoxListClose");
       divRefC.style.display = "block";
   }

   //This function hides the checkboxlist
   function HideMList()
   {
       document.getElementById("divCheckBoxList").style.display = "none";
       document.getElementById("divCheckBoxListClose").style.display = "none";
   }

   //This function finds the checkboxes selected in the list and using them,
   //it shows the selected items text in the textbox (comma separated)
   function FindSelectedItems(sender,textBoxID)
   {
       var cblstTable = document.getElementById(sender.id);
       var checkBoxPrefix = sender.id + "_";
       var noOfOptions = cblstTable.rows.length;
       var selectedText = "";
       for(i=0; i < noOfOptions ; ++i)
       {
          if(document.getElementById(checkBoxPrefix+i).checked)
          {
             if(selectedText == "")
                selectedText = document.getElementById
                                   (checkBoxPrefix+i).parentNode.innerText;
             else
                selectedText = selectedText + "," +
                 document.getElementById(checkBoxPrefix+i).parentNode.innerText;
          }
       }
       document.getElementById(textBoxID.id).value = selectedText;
    }
</script>

well there's your answer:

document.getElementById("divCheckBoxList");

Isn't returning anything, it can't find that element. My first tip is to use Firefox and Firebug so you can actually see the error since Internet Explorer has pretty much every JS error as Object Expected because everything in JS is an object

You are right, ShawnCplus!
The correct form would be: document.getElementById(<%= myControl.ClientID %>')

Thanks =)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.