0

Hi I have a calendar and when I click on the date it opens a modal window where you can add an event to the calendar however to do so I need the date that was clicked on to be passed to the modal so I can add it to my database once the user clicks submit.

As of right now Im doing this by echoing my modal codes for each even so if you look at my source I have 31 modals but Im trying to, by simply passing the date as a variable, reduce it to one modal.

This is the code for my modal:

I wasnt able to format it to show here for some reason so I posted it here: http://paste.ee/p/NKlVY

And this is how I call it:

$sCalTblRows .= '<td class="'.$sClass.'" id=""><a data-toggle="modal" data-date="'.$eventdate.'" href="#myModal">'.$iCurrentDay.'<br></br><br></br></td>';

What would I need to add or change so I can use one modal for all the dates of the month?

user2989367
  • 405
  • 3
  • 11
  • 19
  • you don't use data-date in your modal ? – Lory Huz Jan 08 '14 at 00:13
  • Thats the thing I dont know how, I was told by someone to put data-date in my tag but the person didnt explain how to use it :S – user2989367 Jan 08 '14 at 00:16
  • You need to use JS/jQuery to bind the data, I will show you an example of code – Lory Huz Jan 08 '14 at 00:18
  • you only need eventdate to your modal ? where do you want this value in the modal ? which dom element ? – Lory Huz Jan 08 '14 at 00:21
  • Id like it in a hidden input so when I submit my form I can just call to it using POST. So Im not sure which dom element would be best for that – user2989367 Jan 08 '14 at 00:24
  • What ? I don't understand, why you have a modal so http://paste.ee/p/NKlVY there isn't hidden input here. – Lory Huz Jan 08 '14 at 00:26
  • Yea my bad I posted the code for the modal im trying to make the modal that Im currently using has this But thats the one where im echoing a modal for every date of the month, so where it says value=$eventdate I would Like to have to result of the data-date attribute and thats where Im lost on how to do that – user2989367 Jan 08 '14 at 00:30
  • Ok I answered, my example should output in the modal body but you can change it to the hidden input. Tell me if you have trouble with it – Lory Huz Jan 08 '14 at 00:32

1 Answers1

0

I'm not sure if I understand well your problem but you probably have to use javascript. Actually It can't work

You should have one modal, and when the client choose a date, put this date in the modal in Javascript or jQuery.

Example in jQuery (not tested but this is the logic):

$("td.yourtdclass a" ).on("click", function() {
    var choosen_date = $(this).attr('data-date');
    $('.modal-body').html(choosen_date);
});

Since we have not much informations about your code I can't help more but here is the logic you need ;)

EDIT:

For your example:

html input:

 <input id="event-data" type="hidden" name="date" value="" />

jQuery:

$( "td.yourtdclass a" ).on("click", function() {
   var choosen_date = $(this).attr('data-event');
   $('#event-data').val(choosen_date);
});
Lory Huz
  • 1,557
  • 2
  • 15
  • 23
  • Where do I need to put that code just in some – user2989367 Jan 08 '14 at 00:38
  • I edited for output in a hidden input like you want. Your modal should be in the same page as your code, put the jquery in a script tag at the end of file just before

    endtag. You have to load jquery script before ofc

    – Lory Huz Jan 08 '14 at 00:40
  • Okay and if my link is like i said: '.$iCurrentDay.'

    what would I need to put in td.yourtdclass a since im using a variable already as a class for the td
    – user2989367 Jan 08 '14 at 00:43
  • You need to write the content of this variable. Why you use a PHP variable here ? If $sClass = 'myclass' then you need to have this selector $('td.myclass a'). Or you can also just put a class to all your tags like and replace td.myclass a by .event-link – Lory Huz Jan 08 '14 at 00:47
  • So now if I view the source of my document it should give me something like ? – user2989367 Jan 08 '14 at 00:55
  • Its not :( I dont know if im doing something wrong heres my code: http://paste.ee/p/UzGDQ The link starts at line 196 I put a class on the a like you told me too, I put the js at the end before the

    like you side, this is the source of my page when viewed: http://paste.ee/p/RRoTU as you can see on line 83 theres nothing in the value

    – user2989367 Jan 08 '14 at 01:04
  • replace $(this).attr('data-event'); by $(this).attr('data-date'); And you should put my code in your $(document).ready(function() { – Lory Huz Jan 08 '14 at 01:18
  • How will it show when I view source since when it has no idea which date i click on – user2989367 Jan 08 '14 at 01:27
  • You click on a link and the date should appear in the input thats all. You don't know how to use the console ? – Lory Huz Jan 08 '14 at 08:31
  • If you want to see the value directly you can test the code on a standard input – Lory Huz Jan 08 '14 at 11:16
  • I really dont know what Im doing wrong its still not working :S – user2989367 Jan 08 '14 at 12:22
  • http://jsfiddle.net/p6jcp/ I rewrite my code here, you can test it by click on run then click on a date, it will appear in the input. So you see it's working... – Lory Huz Jan 08 '14 at 12:37
  • Is it possible it doesnt work inside a modal? I put the exact same code you put on jsfiddle, when I view my source each date is like this: 15

    and the input when I click to open the modal is empty.
    – user2989367 Jan 08 '14 at 20:17
  • No it can't be the issue. Plz give me a link to your app online if possible. If you can't, complete client code (no php) – Lory Huz Jan 08 '14 at 20:37
  • http://myschedule.netai.net/indextemp.php itll bring you to the login page you can login with testtes password ilmilm but itll bring you to index.php just click back on indextemp.php thanks a lot for your help – user2989367 Jan 08 '14 at 20:41
  • If you need anything else just let me know – user2989367 Jan 08 '14 at 21:11
  • sorry but the code is hardcore, its seem you copy paste a lot of thing, you load two time jquery, you have an doctype inside another and a lot of things like that wtf ? :p – Lory Huz Jan 08 '14 at 21:11
  • Yea im new to this sorry I plan on cleaning things up before im done. What do you mean with two time jquery, you think that could cause the problem? – user2989367 Jan 08 '14 at 21:14
  • maybe, your code has too much error, look at the source you have two doctype tags (like you have two pages into one file...) For jquery look at your source there is: and Please delete ALL the second page stuff in indextemp (begin line 100) – Lory Huz Jan 08 '14 at 21:22
  • I think I deleted everything that was double – user2989367 Jan 08 '14 at 21:28
  • well I see why it doesn't work for you, look at my previous comment: "replace $(this).attr('data-event'); by $(this).attr('data-date'); And you should put my code in your $(document).ready(function() { " You put my code BEFORE the function, you have to put IN, not after and not before – Lory Huz Jan 08 '14 at 21:37
  • Okay I cleaned it out i removed the body tag and added the html add the end. However it still doesnt show up for me and it didnt work when I tried to view it locally unless i did something wrong :S – user2989367 Jan 08 '14 at 21:46
  • look my previous comment, you don't put my code at the right place – Lory Huz Jan 08 '14 at 21:49