Ok. I tried this but I am having trouble getting it to work.
Firstly, I'm adding the onclick attribute in the code behind. Is there anywhere in particular I should do this? I've tried this in the Page_Init and Page_Load event handlers. Here's the code for this bit:
string rentalDropDownClientID = RentalDropDown.ClientID;
string priceDropDownClientID = PriceDropDown.ClientID;
foreach (ListItem li in BuyLetDropDown.Items)
{
if (li.Value == "Buy" || li.Value == "Select")
{
li.Attributes.Add("Onclick",
"ShowHide('" + priceDropDownClientID + "','on');ShowHide('" + rentalDropDownClientID + "','off')");
}
else if (li.Value == "Rent")
{
li.Attributes.Add("Onclick",
"ShowHide('" + priceDropDownClientID + "','off');ShowHide('" + rentalDropDownClientID + "','on')");
}
}
Then, there's the JavaScript function, which I was a little unsure about:
function ShowHide(dropDownClientID, OnOff)
{
var ele = document.getElementById(dropDownClientID);
if(ele != null)
{
if(OnOff == "on")
{
ele.style.visibility = "visible";
ele.style.display = "block";
}
else
{
ele.style.visibility = "hidden";
ele.style.display = "none";
}
}
}
The JavaScript function is on the webpage (rather than external file).
I changed the BuyLetDropDown's AutoPostBack to false.
However, when I try this out, it does not work.
I must be doing something wrong? Unless it is related to the Ajax UpdatePanel?
The generated source for the dropdowns looks like this:
<p class="db_sidebardropdowntext"> Buy/Let:<br /><select name="ctl00$ContentPlaceHolder2$BuyLetDropDown" id="ctl00_ContentPlaceHolder2_BuyLetDropDown" style="color:Blue;font-size:Smaller;width:90px;">
<option selected="selected" value="Select" Onclick="ShowHide('ctl00_ContentPlaceHolder2_PriceDropDown','on');ShowHide('ctl00_ContentPlaceHolder2_RentalDropDown','off')">Select...</option>
<option value="Buy" Onclick="ShowHide('ctl00_ContentPlaceHolder2_PriceDropDown','on');ShowHide('ctl00_ContentPlaceHolder2_RentalDropDown','off')">Buy</option>
<option value="Rent" Onclick="ShowHide('ctl00_ContentPlaceHolder2_PriceDropDown','off');ShowHide('ctl00_ContentPlaceHolder2_RentalDropDown','on')">Rent</option>
</select>
</p>
<select name="ctl00$ContentPlaceHolder2$PriceDropDown" id="ctl00_ContentPlaceHolder2_PriceDropDown" style="color:Blue;font-size:Smaller;width:128px;">
<option selected="selected" value="Any">Any</option>
<option value="<=£50,000"><=£50,000</option>
<option value="£50,001 - £100,000">£50,001 - £100,000</option>
<option value="£100,001 - £175,000">£100,001 - £175,000</option>
<option value="£175,001 - £250,000">£175,001 - £250,000</option>
<option value="£250,001 - £300,000">£250,001 - £300,000</option>
<option value="£300,001 - £400,000">£300,001 - £400,000</option>
<option value="£400,001 - £500,000">£400,001 - £500,000</option>
<option value="£500,000+">£500,000+</option>
</select>
When I test, only the priceDropDown is ever visible.
Any help appreciated.
Thank you.