CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    160

    javascript calender in Ajax response

    on selection of a value on a drop down box a form is generated through an ajax call. the form has a date field and i have set up a popup calender for the date field. i load the javascript calender function from the onload function of the page that requests the ajax call for the form.

    How can i display the calender pop up by clicking on the text?

    My understanding is that the javascript which loads with onload gets killed when the ajax page is called (php) and when the ajax response comes the object is not alive to kick out the calender.

    body head section (i tried putting it into a function called cal_init and calling that function after the ajax response but that doesnt work.
    Code:
    <script src="SpryAssets/SpryAccordion.js" type="text/javascript"></script>
    
    
    <link href="SpryAssets/SpryAccordion.css" rel="stylesheet" type="text/css" />
    <link href="includes/style.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript">
    var calendar1, calendar2, calendar3; /*must be declared in global scope*/
    /*put the calendar initializations in the window's onload() method*/
    window.onload = function() {
    	cal_init();
    	
    };
    cal_init()
    { alert("hi");
    calendar1 = new Epoch('cal1','popup',document.getElementById('calendar1_container'),false);
    	calendar2 = new Epoch('cal1','popup',document.getElementById('calendar2_container'),false);
    	calendar3 = new Epoch('cal1','popup',document.getElementById('calendar3_container'),false);
    };
    </script>
    </head>

  2. #2
    Join Date
    Jul 2006
    Posts
    297

    Re: javascript calender in Ajax response

    I'm not quite sure what your question is but maybe this will help you figure it out. If i understand correctly the problem you are having is that you're trying to populate a dropdown via AJAX and you're calling the AJAX function on the pages onLoad() function?

    First thing you need to do is make sure that the object you're trying to populate has already been added to the DOM before the AJAX runs.

    body head section (i tried putting it into a function called cal_init and calling that function after the ajax response but that doesnt work.
    Secondly remember that AJAX is asynchronous. Which means if you call a function after you make the AJAX call it does not guarantee that the AJAX will have handled its response before the function gets run. In the following code, cal_init() will run before the AJAX call is complete.

    Code:
    MakeAjaxCall();
    cal_init();
    You need to fire cal_init() after you get the text for the ajax request.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured