Jump to content

clean up widget


dadamssg87

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.