dadamssg87 Posted May 29, 2011 Share Posted May 29, 2011 So i've developed a widget where it displays a calendar with previous and next month links. It uses jquery ajax so the page doesn't have to reload. The way i have it now is like the following. The calendar_javascript.php script produces javascript, basically "document.write("all of the calendar html");. That gets the calendar on the page initially. Then the changeMonth link loads up calendar_html.php which echo's the calendar html in the #calendar div. For this all to work on a page you have to copy paste jquery source code, my changeMonth() link, make a #calendar div, and put the javascript tag in that div. How much can i clean this up? I'd really like to just have some chunk of code to paste once in the body where i want the widget to appear. <html> <script src="http://code.jquery.com/jquery-latest.js"></script> <script> function ChangeMonth(X,Y,Z){ var changemonthlink = "http://localhost:8888/calendars/calendar_html.php?m=" + X + "&y=" + Y + "&i=" + Z; jQuery("#calendar").load(changemonthlink); }; <script> <head> </head> <body> <div id='calendar'> <script type="text/javascript" src="http://localhost:8888/calendars/calendar_javascript.php?i=<?=$cal_id;?>"></script> </div> </body> </html> Link to comment https://forums.phpfreaks.com/topic/237804-clean-up-widget/ Share on other sites More sharing options...
seanlim Posted May 30, 2011 Share Posted May 30, 2011 From what I understand, you can place your ChangeMonth function in your calendar_javascript.php and attach the event handler dynamically. calendar_javascript.php can also change the html of #calendar directly. That way, you will not need to use document.write and won't need to place the <script> tags within the #calendar div. That leaves you with (1) importing calendar_javascript.php with <script> tags at the top of the page, and (2) a #calendar div. Link to comment https://forums.phpfreaks.com/topic/237804-clean-up-widget/#findComment-1222126 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.