Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass parameter to javascript for calendar control

Status
Not open for further replies.

wbodger

Programmer
Apr 23, 2007
769
US
I have this code, which works:

Code:
<script type="text/javascript">
    function openCalendar() {
        window.open('popup-calendar.aspx?ctlid=<%=[b]TextBox1.ClientID[/b] %>', 'Calendar', 'scrollbars=no,resizable=no,width=240,height=220');
        return false;
    }
    function openCalendar2() {
        window.open('popup-calendar.aspx?ctlid=<%=[b]TextBox2.ClientID[/b] %>', '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
 
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 %>);" />
 
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
 
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
 
Thanks, for the info. I will try again and figure out what I am missing or fat-fingered.

wb
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top