2 Replies - 14179 Views - Last Post: 27 November 2009 - 03:15 PM Rate Topic: -----

#1 annacd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-November 09

Hide div using javascript when DropDownList selected Item changes

Posted 27 November 2009 - 02:10 PM

Hi,

I have a DropDownList with two options: Item 1 and Item 2. I have a textBox where the user for the information based on the item he chose in the DropDownList and the text he typed.
After he makes the first search, the information he is searching for is shown in a div. If the user tries to make another search, I need to make the div to disappear when he changes the option in the DropDownList.

I tried the following code:

In ASP.NET:
<asp:DropDownList ID="SearchOptionsDropDownList" runat="server" onselectedIndexChanged="SearchOptionsDropDownList_SelectedIndexChanged" onchange="java script:hideBottomDiv('<%=BottomDiv.ClientID %>')">
		<asp:ListItem Text="Item 1" Value="1" />
		<asp:ListItem Text="Item 2" Value="2" />
	</asp:DropDownList>



In java script:
function hideBottonDiv(divId) {
			document.getElementById(divId).style.display = 'none';
		}



In vb script:hideBottomDiv('<%= " & BottomDiv.ClientID & "%>')")
End Sub


However, when I try changing the selected item in the DropDownList this error message is fired: Microsoft JScript runtime error: Object expected. And the following text is highlighted:

<select name="ctl00$mainCopy$SearchOptionsDropDownList" id="ctl00_mainCopy_SearchOptionsDropDownList" onchange="[color=#CC0000]java script:hideBottomDiv('<%=BottomDiv[/color].ClientID %>')">



What is happening here and why my code is not working?

Thanks a lot,

Ana

This post has been edited by annacd: 27 November 2009 - 02:11 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Hide div using javascript when DropDownList selected Item changes

#2 annacd   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 27-November 09

Re: Hide div using javascript when DropDownList selected Item changes

Posted 27 November 2009 - 02:15 PM

I'm having problems to post the code in VB DOT NET. The code posted is being replaced by some strange code for a reason I don't know.

Anyways, the code in the SearchOptionsDropDownList_SelectedIndexChanged is adding the attribute "onchange" to the SearchOptionsDropDownList using:

SearchOptionsDropDownList.Attributes.Add("onchange", javascriptMethod)



Where javascriptMethod is the same one called on the SearchOptiondropDownList tag.

This post has been edited by annacd: 27 November 2009 - 02:19 PM

Was This Post Helpful? 0
  • +
  • -

#3 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Hide div using javascript when DropDownList selected Item changes

Posted 27 November 2009 - 03:15 PM

Since the div is an HTML element and not an ASP.NET server control you don't need to pass the ClientID property. Just pass the name of the DIV.

<asp:DropDownList ID="SearchOptionsDropDownList" runat="server" onselectedIndexChanged="SearchOptionsDropDownList_SelectedIndexChanged"		onchange="java script:hideBottomDiv('BottomDiv')">


I also noticed the name of your function is spelled 'hideBottonDiv', but your function call is spelled "hideBottomDiv". Your going to need to correct the typo.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1