Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Pass parameter to javascript for calendar control

Pass parameter to javascript for calendar control

Pass parameter to javascript for calendar control

I have this code, which works:


<script type="text/javascript">
    function openCalendar() {
        window.open('popup-calendar.aspx?ctlid=<%=TextBox1.ClientID %>', 'Calendar', 'scrollbars=no,resizable=no,width=240,height=220');
        return false;
    function openCalendar2() {
        window.open('popup-calendar.aspx?ctlid=<%=TextBox2.ClientID %>', 'Calendar', 'scrollbars=no,resizable=no,width=240,height=220');
        return false;
    <form id="form1" runat="server">
    Start Date:<br />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
    <asp:Button ID="Button1"  runat="server" Text="..."  OnClientClick="javascript:return openCalendar();" />
    End Date:<br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  
    <asp:Button ID="Button2"  runat="server" Text="..."  OnClientClick="javascript:return openCalendar2();" />

But I dislike having to have two functions because I could net get it to pull the ID of the associated textbox. How would I replace the bolded area in the javascript function so I could successfully use just one opencalendar function and still pass the controlid back to populate the correct textbox?


RE: Pass parameter to javascript for calendar control

Pass a parameter to your function:


function openCalendar(textboxID) {
        window.open('popup-calendar.aspx?ctlid=' + textboxID, 'Calendar', 'scrollbars=no,resizable=no,width=240,height=220');
        return false;


<asp:Button ID="Button1"  runat="server" Text="..."  OnClientClick="javascript:return openCalendar(<%=TextBox1.ClientID %>);" />
   <asp:Button ID="Button2"  runat="server" Text="..."  OnClientClick="javascript:return openCalendar2(<%=TextBox2.ClientID %>);" /> 

RE: Pass parameter to javascript for calendar control

Hmm... I tried something like this with no luck and then I tried this exactly with no luck. I also tried this exactly with no love. I tried modifications I could think of and still no luck. No error, it just did nothing.


RE: Pass parameter to javascript for calendar control

debug your code. it works for me. put an alert in the function to make sure you are calling it correctly
if that works, alert out the texboxid passed in

RE: Pass parameter to javascript for calendar control

Thanks, for the info. I will try again and figure out what I am missing or fat-fingered.


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close