INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

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.

Jobs

Pass parameter to javascript for calendar control

Pass parameter to javascript for calendar control

(OP)
I have this code, which works:

CODE

<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;
    }
</script>
</head>
<body>
    <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();" />
        <p></p>
    End Date:<br />
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  
    <asp:Button ID="Button2"  runat="server" Text="..."  OnClientClick="javascript:return openCalendar2();" />
    
    </form>
</body> 

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?

Thanks,
wb

RE: Pass parameter to javascript for calendar control

Pass a parameter to your function:

CODE

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

CODE

<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

(OP)
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.

Thanks,
Willie

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

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

wb

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!

Resources

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