locked
Java Script Problem RRS feed

  • Question

  • User-1999404714 posted

    Hi all,

     Suppose i Have a Java Script In Which It Validate Dropdown's 0 index onchange...

    the first parameter is 'this', means dropdown id but how to pass div id which is runat="server"

    my function

    function OnChangeDropDown( DropDown, DivError )
    {
    var DivError1 = document.getElementById( DivError )
    if ( DropDown.value == "0" )
    {
    DivError1.style.display = '';
    DropDown.focus();
    return false;
    }
    else
    {
    DivError1.style.display = 'none';
    return false;
    }
    }

    calling Style...
    onchange="return OnChangeDropDown(this,<%# DivError1.ClientID %>)"


    Now Problem is How To Pass ControlID IN Java Script Function.......


    Hope For The Best


    Anudeep Jaiswal
    09891599687
    Noida
    India

    Saturday, January 10, 2009 2:42 AM

Answers

  • User-1319812544 posted

    ya this will happen, I want to say sorry again,

    you cant use server code tag in server controls (if they have runat="server")

    Do one thing

    on code behind page : go to page load and thenwrite this line

    yourcontrolID.Attributes.Add("onchange","return OnChangeDropDown(this,\""+yourcontrolID.clientID+"\");");

    this will work

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 4:29 AM
  • User-1319812544 posted

    ya, it is : agrawalbs@yahoo.com

    use the following line- as edited above also

    yourcontrolID.Attributes.Add("onchange","return OnChangeDropDown(this,\""+yourcontrolID.clientID+"\");"); 

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 4:33 AM
  • User-768391503 posted

     The first way you posted it, the code should have been like this:

    OnChangeDropDown(this,'<%= DivError1.ClientID %>')"

    Each of the solutions given above with this style seemed to be missing something or had a typo.

    Eric

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 8:18 AM
  • User798903548 posted

    The trick is that using this in the markup does not always work:
         <asp:DropDownList id="DropDownList1" runat="server" onchange="OnChangeDropDown(this, '<%= DivError1.ClientID %>')"></asp:DropDownList>
    sometimes, you will get '<%= DivError1.ClientID %>' literally in the markup.

    Instead, always use the CodeBehind Page_Load handler to attach event handlers that need IDs added.
         DropDownList1.Attributes.Add("onchange", string.Format("OnChangeDropDown(this, '{0}');", DivError1.ClientID))

    NC...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 11:24 AM

All replies

  • User-1319812544 posted

    Anudeep:

    what is the poblem? Is the above function not working?

    Which controlID you want to pass, you are already passing the error div ID to the function!!!

    Saturday, January 10, 2009 4:07 AM
  • User-1999404714 posted

    Thanks....

    For Replying...

     

     

    But i can not pass  The Div Id ...

     

    onchange="return OnChangeDropDown(this,<%# DivError1.ClientID %>)"

     

    there is a syntax error.......

     

    reply.....

     

    Hope for the best............

    Saturday, January 10, 2009 4:12 AM
  • User-1319812544 posted

    Sorry, I overlooked, the mistake is here

    OnChangeDropDown(this,<%<STRIKE># </STRIKE>DivError1.ClientID %>)"   should be

    OnChangeDropDown(this,<%= DivError1.ClientID %>)"

    Saturday, January 10, 2009 4:16 AM
  • User-1319812544 posted

    There is one more mistake, the correct one is:

    onchange="return OnChangeDropDown(this,'<%= DivError1.ClientID %>')"

    put single quotes also

    Saturday, January 10, 2009 4:22 AM
  • User-1999404714 posted

     During rendring it become

     onchange="return OnChangeDropDown(this,&lt;%= DivError.ClientID %> )"


    Saturday, January 10, 2009 4:22 AM
  • User-1999404714 posted

     Can i Have Your Personal E Mail ID plz.........

    Saturday, January 10, 2009 4:28 AM
  • User-1319812544 posted

    ya this will happen, I want to say sorry again,

    you cant use server code tag in server controls (if they have runat="server")

    Do one thing

    on code behind page : go to page load and thenwrite this line

    yourcontrolID.Attributes.Add("onchange","return OnChangeDropDown(this,\""+yourcontrolID.clientID+"\");");

    this will work

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 4:29 AM
  • User-1319812544 posted

    ya, it is : agrawalbs@yahoo.com

    use the following line- as edited above also

    yourcontrolID.Attributes.Add("onchange","return OnChangeDropDown(this,\""+yourcontrolID.clientID+"\");"); 

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 4:33 AM
  • User-1999404714 posted

     i already used this....

    is there any way to bind that function in HTML or aspx file.....

    Saturday, January 10, 2009 4:36 AM
  • User-1319812544 posted

    you said you had already used it , but was is the problem ? It slould work fine....

    did you see the html source code? it should come properly

    paste the code which you tried in the code behind page

    Saturday, January 10, 2009 4:39 AM
  • User-1999404714 posted

     Have Gmail account

     

    add me ... My Gmail id is anudeep.mca@gmail.com

    Lets Have Some Chat on this topic

     

    Saturday, January 10, 2009 4:43 AM
  • User-1319812544 posted

    wait then , let me install Gtalk, my ID on gmail is same agrawalbs.

    or you can come on orkut, if it is ok with u

    Saturday, January 10, 2009 4:46 AM
  • User-1319812544 posted

    you mailed me the code , is it throwing erroe the "Object reference not found" ??

    Saturday, January 10, 2009 4:49 AM
  • User-768391503 posted

     The first way you posted it, the code should have been like this:

    OnChangeDropDown(this,'<%= DivError1.ClientID %>')"

    Each of the solutions given above with this style seemed to be missing something or had a typo.

    Eric

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 8:18 AM
  • User798903548 posted

    The trick is that using this in the markup does not always work:
         <asp:DropDownList id="DropDownList1" runat="server" onchange="OnChangeDropDown(this, '<%= DivError1.ClientID %>')"></asp:DropDownList>
    sometimes, you will get '<%= DivError1.ClientID %>' literally in the markup.

    Instead, always use the CodeBehind Page_Load handler to attach event handlers that need IDs added.
         DropDownList1.Attributes.Add("onchange", string.Format("OnChangeDropDown(this, '{0}');", DivError1.ClientID))

    NC...

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, January 10, 2009 11:24 AM