How to refer to aspx hidden field from a Java script

R

RuthG

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.
 
T

Thomas 'PointedEars' Lahn

RuthG said:
[...] 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
 
R

RuthG

RuthG said:
[...] 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[].
 
T

Thomas 'PointedEars' Lahn

RuthG said:
Thomas said:
RuthG said:
[...] 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.

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
 
M

Michael J. Ryan

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%>']
 
M

Michael J. Ryan

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,241
Members
46,831
Latest member
RusselWill

Latest Threads

Top