Saturday, March 24, 2012

Watermark extender type function on a dropdown?

Hi there,

I have 5 textboxes all using the watermark extender to tell the user that these fields are required and has some colour formatting. I would also like to do the same type of thing to a dropdown but it doesn't work, can anyone suggest a method I can use?

Thank you for your time

Here's just one suggestion:

<%@. Page Language="VB" AutoEventWireup="false" CodeFile="Default4.aspx.vb" Inherits="Default4" %><%@. Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %><%@. Register Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Namespace="System.Web.UI" TagPrefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title> <script type="text/javascript"> function ddlChange(ddl) { if (ddl.selectedIndex == 0) { ddl.style.backgroundColor = 'Yellow'; ddl.options[0].innerText = 'Please select...'; } else { ddl.style.backgroundColor = ''; ddl.options[0].innerText = ''; } } </script></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <asp:DropDownList ID="DropDownList1" runat="server" style="background-color:Yellow;" onchange="ddlChange(this)"> <asp:ListItem Value="">Please select...</asp:ListItem> <asp:ListItem>Option A</asp:ListItem> <asp:ListItem>Option B</asp:ListItem> <asp:ListItem>Option C</asp:ListItem> </asp:DropDownList> </div> </form></body></html>

Thats cool thank you for that! one question, can css be used in place of hardcoding the color?

Thanks again


Pretty simply really, use the same javascript example as above

Create a new Required style for the dropdown e.g background-color:red; have that as the dropdown list's default css then using this piece of javascript be able to swap between the 2 based on Item value

function ddlChange(ddl)

{
if (ddl.selectedIndex == 0)
{
ddl.className ='RequiredCSS'
}
else
{
ddl.className ='SelectedCSS';
}
}

Hope this helps you out.


awesome thank you

Boy, diverdan, I do all the hard typing and you get all the credit!

Just kidding.

Happy Holidays, all...


Sorry!!!! I thought I had clicked the both of you!

Thank you for your help! have a great holiday!

No comments:

Post a Comment