accessing <asp:TemplateField <EditItemTemplate><asp:DropDownList via javascript

have a detailsview with a template field with a dropdown list.

I have attached a javascript function with:
foreach (DetailsViewRow dvr in dvEditPD.Rows)
        {
            ((DropDownList)dvr.FindControl("ddlSource")).Attributes.Add("onchange", "OtherSource()");
        }

and this fires...tested with a simple alert.

not sure if I should post this in the javascript forums...but....anyways.

in regular html aspx page I used the following to show/hide a text box based on selected value of ddlSource

{
var i=document.forms[0].elements['ddlSource'].selectedIndex
if (i==9) {
    document.getElementById('otherTextDiv').style.display = '';
    }
    else
    {
    document.getElementById('otherTextDiv').style.display = 'none';
    }
}

<td style="height: 25px">
   <div id="otherTextDiv" runat="server" style="DISPLAY: none" >
      <asp:TextBox id="txtOtherSource" runat="server">Plese Specify</asp:TextBox>
   </div>
</td>

now that I'm using a details view I can't figure out how to get into the templatefield to hide/show the div

                <asp:TemplateField>
                    <ItemTemplate>
                        <div id="otherTextDiv" runat="server" style="DISPLAY: none">
                            <asp:TextBox id="txtOtherSource" runat="server">Plese Specify</asp:TextBox>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>

basically I need to show/hide a text box if selection is 'Other' but need to do it client side, no postback.

if I need to move this to javascript, let me know.

high points, cause kind of urgent

thanx,
LVL 1
heincpaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mppetersCommented:
You should pass in the client-side ID of the control to your javascript function.

foreach (DetailsViewRow dvr in dvEditPD.Rows)
        {
          DropDownList ddl =  ((DropDownList)dvr.FindControl("ddlSource"))
          ddl.Attributes.Add("onchange", "OtherSource('" + ddl.ClientID + "')");
        }

Then use that to find the control in javascript:

function OtherSource(clientId) {
var i=document.forms[0].elements[clientId].selectedIndex

Either that, or use the keyword 'this' to pass in an already instantiated instance of the control in javascript.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
heincpaAuthor Commented:
I was so close...thanx for setting it straight!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.