How to refer to aspx hidden field from a Java script

Discussion in 'Javascript' started by RuthG, Jun 17, 2009.

  1. RuthG

    RuthG Guest

    I am trying to get a date (using a calendar pop up) from the user and
    use that date as a parameter into a SQL Server stored procedure. I
    tried using an asp hidden field, with an OnValueChanged procedure in
    the code behind file, and an input button which calls the Javascript
    calendar pop up and changes the date in the hidden field. The page is
    based on a Master page and the fields are in ContentPlaceHolder3. Here
    are the two fields:

    <asp:HiddenField ID="DelayDate"
    runat="server" /><a id="anchor1" name="anchor1"> </a>
    <input id="ButtonDelay" name="ButtonDelay"
    type="button" value="Delay" runat="server"
    onclick = "cal1.select(document.forms
    [0].ct100$ContentPlaceHolder3$DelayDate,'anchor1','MM/dd/yyyy');return
    false;"
    style="font-family:Tw Cen MT Condensed
    Extra Bold" />

    The calendar javascript cannot locate the input parameter. It gives me
    "inputobj undefined", where inputobj is the first argument to the
    select function. I tried it three ways:
    document.forms[0].DelayDate
    document.forms[0].ct100_ContentPlaceHolder3_DelayDate
    document.forms[0].ct100$ContentPlaceHolder3$DelayDate

    I checked with firebug and there is only one form, the one generated
    by asp. The id had the underline and the name the $.
    There are also 2 divs, each with a table. The button is in the first
    row of the 2nd table. I tried with the hidden field there and also
    above the 2nd table, both with _ and $. I got the same error.
     
    RuthG, Jun 17, 2009
    #1
    1. Advertising

  2. RuthG wrote:
    > [...] Here are the two fields:
    >
    > <asp:HiddenField ID="DelayDate"


    As it is apparently XML-based, should that not be lowercase -- `id='?

    > runat="server" /><a id="anchor1" name="anchor1"> </a>
    > <input id="ButtonDelay" name="ButtonDelay"
    > type="button" value="Delay" runat="server"
    > onclick = "cal1.select(document.forms
    > [0].ct100$ContentPlaceHolder3$DelayDate,'anchor1','MM/dd/yyyy');return
    > false;"


    There should not be whitespace before and after the `='.

    > style="font-family:Tw Cen MT Condensed
    > Extra Bold" />


    You should use document stylesheets instead of the `style' attribute.

    > The calendar javascript cannot locate the input parameter. It gives me
    > "inputobj undefined", where inputobj is the first argument to the
    > select function.


    So, what is the `select' "function"? It is not a DOM built-in for sure.

    > I tried it three ways:
    > document.forms[0].DelayDate
    > document.forms[0].ct100_ContentPlaceHolder3_DelayDate
    > document.forms[0].ct100$ContentPlaceHolder3$DelayDate
    >
    > I checked with firebug and there is only one form, the one generated
    > by asp.


    Firebug('s HTML tab) can only show what was parsed. Use the Source, Luke.

    > The id had the underline and the name the $.
    > There are also 2 divs, each with a table. The button is in the first
    > row of the 2nd table. I tried with the hidden field there and also
    > above the 2nd table, both with _ and $. I got the same error.


    Check the markup which ASP .NET generates and use
    document.forms[0].elements["..."] on it. Note that
    duplicate names create NodeLists in the document tree.


    HTH

    PointedEars
     
    Thomas 'PointedEars' Lahn, Jun 17, 2009
    #2
    1. Advertising

  3. RuthG

    RuthG Guest

    On Jun 17, 4:19 pm, Thomas 'PointedEars' Lahn <>
    wrote:
    > RuthG wrote:
    > > [...] Here are the two fields:

    >
    > >                         <asp:HiddenField ID="DelayDate"

    >
    > As it is apparently XML-based, should that not be lowercase -- `id='?
    >
    > > runat="server" /><a id="anchor1" name="anchor1"> </a>
    > >                         <input id="ButtonDelay" name="ButtonDelay"
    > > type="button" value="Delay"  runat="server"
    > >                          onclick = "cal1.select(document.forms
    > > [0].ct100$ContentPlaceHolder3$DelayDate,'anchor1','MM/dd/yyyy');return
    > > false;"

    >
    > There should not be whitespace before and after the `='.
    >
    > >                            style="font-family:Tw Cen MT Condensed
    > > Extra Bold" />

    >
    > You should use document stylesheets instead of the `style' attribute.
    >
    > > The calendar javascript cannot locate the input parameter. It gives me
    > > "inputobj undefined", where inputobj is the first argument to the
    > > select function.

    >
    > So, what is the `select' "function"?  It is not a DOM built-in for sure..
    >
    > > I tried it three ways:
    > > document.forms[0].DelayDate
    > > document.forms[0].ct100_ContentPlaceHolder3_DelayDate
    > > document.forms[0].ct100$ContentPlaceHolder3$DelayDate

    >
    > > I checked with firebug and there is only one form, the one generated
    > > by asp.

    >
    > Firebug('s HTML tab) can only show what was parsed.  Use the Source, Luke.
    >
    > > The id had the underline and the name the $.
    > > There are also 2 divs, each with a table. The button is in the first
    > > row of the 2nd table. I tried with the hidden field there and also
    > > above the 2nd table, both with _ and $. I got the same error.

    >
    > Check the markup which ASP .NET generates and use
    > document.forms[0].elements["..."] on it.  Note that
    > duplicate names create NodeLists in the document tree.
    >
    > HTH
    >
    > PointedEars


    Thanks for your comments. Actually, as I found after looking more
    carefully at the source, I had typed the number "1" instead of the
    letter "l" in the name. I thought it was "ct"100 instead of "ctl"00. I
    didn't need .elements[].
     
    RuthG, Jun 17, 2009
    #3
  4. RuthG wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> RuthG wrote:
    >>> [...] There are also 2 divs, each with a table. The button is in the
    >>> first row of the 2nd table. I tried with the hidden field there and
    >>> also above the 2nd table, both with _ and $. I got the same error.

    >> Check the markup which ASP .NET generates and use
    >> document.forms[0].elements["..."] on it. Note that duplicate names
    >> create NodeLists in the document tree. [...]

    >
    > Thanks for your comments.


    You're welcome. Thanks for not full-quoting them next time.

    <http://jibbering.com/faq/#posting>

    > Actually, as I found after looking more carefully at the source, I had
    > typed the number "1" instead of the letter "l" in the name. I thought it
    > was "ct"100 instead of "ctl"00.


    I see.

    > I didn't need .elements[].


    You should use it anyway as it is both backwards-compatible and
    standards-compliant. The abbreviated referencing, on the other
    hand, is proprietary.

    <http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>


    PointedEars
     
    Thomas 'PointedEars' Lahn, Jun 17, 2009
    #4
  5. On 6/17/2009 12:14 PM, RuthG wrote:
    > I am trying to get a date (using a calendar pop up) from the user and
    > use that date as a parameter into a SQL Server stored procedure. I
    > tried using an asp hidden field, with an OnValueChanged procedure in
    > the code behind file, and an input button which calls the Javascript
    > calendar pop up and changes the date in the hidden field. The page is
    > based on a Master page and the fields are in ContentPlaceHolder3. Here
    > are the two fields:
    >
    > <asp:HiddenField ID="DelayDate"
    > runat="server" /><a id="anchor1" name="anchor1"> </a>
    > <input id="ButtonDelay" name="ButtonDelay"
    > type="button" value="Delay" runat="server"
    > onclick = "cal1.select(document.forms
    > [0].ct100$ContentPlaceHolder3$DelayDate,'anchor1','MM/dd/yyyy');return
    > false;"


    try...
    "cal1.select(document.getElementById('<%=DelayDate.ClientId%>'), ...."
    or...
    document.forms[0].elements['<%=DelayDate.ClientId%>']


    --
    Michael J. Ryan - http://tracker1.info/

    .... FRA #094: Females and finances don't mix.
     
    Michael J. Ryan, Jun 18, 2009
    #5
  6. On 6/17/2009 2:26 PM, RuthG wrote:
    >> Check the markup which ASP .NET generates and use
    >> document.forms[0].elements["..."] on it. Note that
    >> duplicate names create NodeLists in the document tree.

    >
    > Thanks for your comments. Actually, as I found after looking more
    > carefully at the source, I had typed the number "1" instead of the
    > letter "l" in the name. I thought it was "ct"100 instead of "ctl"00. I
    > didn't need .elements[].


    I would suggest injecting ControlName.ClientId, also .elements is needed,
    assuming you need more than IE support.

    --
    Michael J. Ryan - http://tracker1.info/

    .... B5: It's all true. And of course, it's all a lie.
     
    Michael J. Ryan, Jun 18, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeff
    Replies:
    2
    Views:
    2,672
    Coskun Sunali [MVP]
    Jul 24, 2009
  2. Rick
    Replies:
    3
    Views:
    8,351
    Alexey Smirnov
    Apr 13, 2010
  3. GavMc
    Replies:
    4
    Views:
    360
    Evertjan.
    Sep 22, 2005
  4. Roy Adams

    writing from hidden field to text field

    Roy Adams, Dec 20, 2004, in forum: Javascript
    Replies:
    1
    Views:
    208
  5. Roy Adams
    Replies:
    3
    Views:
    276
    Dr John Stockton
    Dec 21, 2004
Loading...

Share This Page