Extract PHP array value in for loop and pass to JQuery -


*edited format

i found php code calendar online , attempting create on click event set date user chooses variable (which later used in database query).

as of want isolate specific day , return value, far can return entire array (1 2 3 4, 5, etc). there way pass particular $list_day value of day selected?

the particular loop in question:

for($list_day = 1; $list_day <= $days_in_month; $list_day++):         $calendar.= '<td class="calendar-day">';             /* add in day number */             $calendar.= '<div class="day-number">'.$list_day.'</div>'; 

full program code:

<!doctype html>     <html>     <head>     <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>         <script>             $(document).ready(function(){                 $("div").click(function(){                     alert($('.calendar-day').text());                         });                     });          </script>     <style>         table.calendar                      { border-left:1px solid #999; }         tr.calendar-row                     {  }         td.calendar-day                     { min-height:80px; font-size:11px; position:relative; } * html div.calendar-day { height:80px; }         td.calendar-day-np                  { background:#eee; min-height:80px; } * html div.calendar-day-np { height:80px; }         td.calendar-day-head                { background:#ccc; font-weight:bold; text-align:center; width:35px; padding:5px; border-bottom:1px solid #999; border-top:1px solid #999; border-right:1px solid #999; }         div.day-number:hover                { background:#eceff5; }         div.day-number                      { background:#ffffff; padding:5px; color:#999; font-size:20px; font-weight:bold; float:right; margin:-5px -5px -5px -5px; width:40px; text-align:center; }         /* shared */         td.calendar-day, td.calendar-day-np { width:35px; padding:5px; border-bottom:1px solid #999; border-right:1px solid #999; }     </style>     </head> </html>  <?php /* draws calendar */ function draw_calendar($month,$year){      /* draw table */     $calendar = '<table cellpadding="0" cellspacing="0" class="calendar">';      /* table headings */     $headings = array('su','m','t','w','th','f','sa');     $calendar.= '<tr class="calendar-row"><td class="calendar-day-head">'.implode('</td><td class="calendar-day-head">',$headings).'</td></tr>';      /* days , weeks vars ... */            $running_day = date('w',mktime(0,0,0,$month,1,$year));            $days_in_month = date('t',mktime(0,0,0,$month,1,$year));            $days_in_this_week = 1;            $day_counter = 0;            $dates_array = array();      /* row week 1 */     $calendar.= '<tr class="calendar-row">';      /* print "blank" days until first of current week */     for($x = 0; $x < $running_day; $x++):         $calendar.= '<td class="calendar-day-np"></td>';         $days_in_this_week++;     endfor;      /* keep going days.... */     for($list_day = 1; $list_day <= $days_in_month; $list_day++):         $calendar.= '<td class="calendar-day">';             /* add in day number */             $calendar.= '<div class="day-number">'.$list_day.'</div>';              /** query database entry day !!  if matches found, print them !! **/             $calendar.= str_repeat('<p> </p>',2);      $calendar.= '</td>';         if($running_day == 6):             $calendar.= '</tr>';             if(($day_counter+1) != $days_in_month):                 $calendar.= '<tr class="calendar-row">';             endif;             $running_day = -1;             $days_in_this_week = 0;         endif;         $days_in_this_week++; $running_day++; $day_counter++;      endfor;      /* finish rest of days in week */     if($days_in_this_week < 8):         for($x = 1; $x <= (8 - $days_in_this_week); $x++):             $calendar.= '<div><td class="calendar-day-np"> </td></div>';         endfor;     endif;      /* final row */     $calendar.= '</tr>';      /* end table */     $calendar.= '</table>';      /* done, return result */     return $calendar; }  /* sample usages */ echo '<h2>november 2014</h2>'; echo draw_calendar(11,2014);  echo date('t',mktime(0,0,0,$month,1,$year));  ?> 

your issue jquery selector using day.

instead of this, returns div elements class name:

$('.calendar-day').text()

use (literally):

$(this).text()

that return text of particular div clicked.


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -