2

I am new in smarty template I have added calendar, I just want to pass the date of calendar to other page.

For example:
When a user clicks on the 24-12-2012 date then I need a url like in this format:
`eventpost.php?ed=24-12-2012``

I have calendar.tpl file:

$('#calendar').fullCalendar({
    dayClick: function (date, allDay, jsEvent, view) {
        var myJsDate = date;
        var dispDate = myJsDate.getDate() + '-' + (myJsDate.getMonth() + 1) + '-' + myJsDate.getFullYear(); // 24-12-2012
        var det = dispDate
        $("#currentDate").val(dispDate);
        $('#offDayPopUp').dialog({
            autoOpen: true,
            modal: true,
            resizable: false,
            width: 300,
            height: 180,
            draggable: false
        });
        $('#calmonth_' + myJsDate.getMonth()).addClass('cal_month_active');
    },

HTML:

<div id="offDayPopUp" class="offDayDialog" title="Create Event,Commitment,Visiting Area.">
    <div class="CrateDiv">
        <div style="float:left; padding-right:10px;"><b>Date :</b></div>
        <div><input type="text" name="currentDate" id="currentDate" readonly="readonly" /></div>
        <ul>
            <li><a href="{$cfgRoot}/event/eventPost.php"><b>Create A New Event.</b></a></li>
            <li><a href="{$cfgRoot}/commitment/commitment.php"><b>Create A New Commitment.</b></a></li>
            <li><a href="{$cfgRoot}/area/areaPost.php"><b>Create A New Visiting Area.</b></a></li>
        </ul>
    </div>
</div>

I just want to pass that date from JavaScript to url like:

eventPost.php?ed=24-12-2012
commitment.php?ed=24-12-2012
areaPost.php?ed=24-12-2012
5
  • Why don't you add the date over PHP? That'd be way more easy and faster. Commented Dec 14, 2012 at 8:36
  • php not work in tpl file. how can i add php code between {literal}{/literal} function Commented Dec 14, 2012 at 8:39
  • 1
    you can write php code between {php}{/php} Commented Dec 14, 2012 at 8:39
  • @danishhashmi i know but how? can you please explain because when i take {php} in javascript then javascript represent this as javascript code Commented Dec 14, 2012 at 8:51
  • you need to end {literal}javascript code {/literal} start {php} php code then end {/php} {literal} javascript code {/literal} Commented Dec 14, 2012 at 9:05

2 Answers 2

2

Following danish hasmi's possibility to use PHP, better use PHP like this. Javascript isn't meant to be used for data manipulation that can be done serverside.

//[...]
<li><a href="{$cfgRoot}/event/eventPost.php?ed={php}echo date('d-m-Y',mktime());{/php}"><b>Create A New Event.</b></a></li>
//[...]

See mktime on php.net to adjust the mktime-parameter and set it on your wanted date.

//Update

Even though it makes more sense to use PHP, this is how you'd do it in Javascript for your sake.

$('#calendar').fullCalendar({
    dayClick: function (date, allDay, jsEvent, view) {
        var myJsDate = date;
        var dispDate = myJsDate.getDate() + '-' + (myJsDate.getMonth() + 1) + '-' + myJsDate.getFullYear(); // 24-12-2012

        $(".CrateDiv > ul").find("li").each(function() {
           var atmhref = $("a",this).attr("href");
           $("a",this).attr("href",atmhref+"?ed="+dispDate);
        });
        //...
Sign up to request clarification or add additional context in comments.

4 Comments

i dont want to pass today's date.. as per my question i want to pass any date which is in calendar
I added the possibility to set it to a wanted date.
no, i just want to pass that javascript value behind the url.
just one problem with that code. when i click on the 1st box the date appear in URL is fine. but when i click on the 2nd box then the date is appear two time....for ex.... 1) eventPost.php?ed=19-12-2012 (this is ok but 2nd time).... 2) eventPost.php?ed=19-12-2012?ed=20-12-2012. (previous date not clear) if possible than pls help me how to clear the previous date....Thanks in advance
1

Try this way,You can use onclick event and pass the selected date using Javascript function

<script>
 {literal}
 function golink(type) {
   var selecteddate = $("#currentDate").val();
   if(type=='event'){
       location.href="http://www.mysite.com/event/eventPost.php?ed="+selecteddate;
    }
   if(type=='commitment'){
       location.href="http://www.mysite.com/commitment/commitment.php?ed="+selecteddate;
    }
  if(type=='area'){
       location.href="http://www.mysite.com/area/areaPost.php?ed="+selecteddate;
    }
 }
  {/literal}
</script>


<div id="offDayPopUp" class="offDayDialog" title="Create Event,Commitment,Visiting Area.">
    <div class="CrateDiv">
        <div style="float:left; padding-right:10px;"><b>Date :</b></div>
        <div><input type="text" name="currentDate" id="currentDate" readonly="readonly" /></div>
        <ul>
            <li><a href="#" onclick="golink('event')"><b>Create A New Event.</b></a></li>
            <li><a href="#" onclick="golink('commitment')"><b>Create A New Commitment.</b></a></li>
            <li><a href="#" onclick="golink('area')"><b>Create A New Visiting Area.</b></a></li>
        </ul>
    </div>
</div>

5 Comments

thanks for this code... but it is not working because we can not take onclick event in .tpl file directly. do you have any idea regarding this?
@PrinceBijvani you can very much use onclick in .tpl file. what error are you getting
@PrinceBijvani try my updated code, if you declaring script inside template file you need to escape it using literal tag or write script in external js page
@PrinceBijvani check this link jsfiddle.net/zBtNk/1 , its working. can you be more specific about your problem
@PrinceBijvani can you paste exact code here. i will try it on my side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.