Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Contributor FARAZFRANK

    (@farazfrank)

    Hi Anand,

    Sorry! but you can’t do like this.

    Post these variable via Ajax to use them.

    Like that (Run JS Postmyvariable function code on any event):

    function Postmyvariable() {
      var name = jQuery("#Name-Field-ID").val();
      var start_time = jQuery("#St-Time-Field-ID").val();
      var end_time = jQuery("#End-Time-Field-ID").val();
      var date = jQuery("#Date-Field-ID").val();
      Datastring = "action=variableposting&Name=" + name + "&StartTime=" + start_time + "&EndTime=" + end_time + "&Date=" + start_date;
      var url = location.href;
      jQuery.ajax({
          dataType : 'html',
          type: 'POST',
          url : url,
          cache: false,
          data : Datastring,
          complete : function() {  },
          success: function(data) {
              alert('variable posted');
          }
      });
    }

    Get Posted Variable

    <?php
    if(isset($_POST['action']) == "variableposting") {
         $name = $_POST['Name'];
         $start_time = $_POST['StartTime'];
         $end_time = $_POST['EndTime'];
         $date= $_POST['Date'];
         // now here you can use these variables in query
    }
    ?>

    I hope this will help a lot for you.

    Kind Regards
    Frank

    Thread Starter Anand Kr mishra

    (@anand-kr-mishra)

    Hi Frank, Thanks you so much for quick reply…

    I am using the given solution in my code but it is not working

    [ Moderator note: please wrap code in backticks or use the code button. ]

    jQuery('#next1').click(function(){
    		//Hiding the selection of specility and doctors//
    			jQuery('.apcal_modal-info').hide();
    			jQuery('.apcal_modal-body').hide();
    			jQuery('#next11').show();
    			var serviceId= jQuery('#service').val();
    			var doctorName= jQuery('#doctorName').val();
    			var appdate= jQuery('#appdate').val();
    			var currenturl = jQuery(location).attr('href');
    			var url = currenturl;
    			var Datastring = "action=getServiceid&serviceId=" + serviceId;
    			<strong>jQuery.ajax({
    			      dataType : 'html',
    			      type: 'POST',
    			      url : url,
    			      cache: false,
    			      data : Datastring,
    			      complete : function() {  },
    			      success: function(data) {
    				  //alert(data);
    			      }
    			  });</strong>
    			//alert("id="+serviceId+" name="+doctorName+" appdate="+appdate);
    		//Hiding the selection of specility and doctors//
    	jQuery('#calendar').fullCalendar({
    		header: {
    			left: 'prev,next today',
    			center: 'title',
    			right: 'agendaWeek'
    		},
    		editable: false,
    		weekends: true,
    		timeFormat: 'H:mm',
    		axisFormat: 'H:mm',
    		<?php $AllCalendarSettings = unserialize(get_option('apcal_calendar_settings')); ?>
    		firstDay: <?php if($AllCalendarSettings['calendar_start_day'] != '') echo $AllCalendarSettings['calendar_start_day']; else echo "1"; ?>,
    		slotMinutes: <?php if($AllCalendarSettings['calendar_slot_time'] != '') echo $AllCalendarSettings['calendar_slot_time']; else echo "15"; ?>,
    		defaultView: '<?php if($AllCalendarSettings['calendar_view'] != '') echo $AllCalendarSettings['calendar_view']; else echo "month"; ?>',
    		minTime: <?php if($AllCalendarSettings['day_start_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_start_time'])); else echo "8"; ?>,
    
    		maxTime: <?php  if($AllCalendarSettings['day_end_time'] != '') echo date("G", strtotime($AllCalendarSettings['day_end_time'])); else echo "20"; ?>,
    		monthNames: ["<?php _e("januari", "appointzilla"); ?>","<?php _e("februari", "appointzilla"); ?>","<?php _e("mars", "appointzilla"); ?>","<?php _e("April", "appointzilla"); ?>","<?php _e("Maj", "appointzilla"); ?>","<?php _e("juni", "appointzilla"); ?>","<?php _e("juli", "appointzilla"); ?>", "<?php _e("augusti", "appointzilla"); ?>", "<?php _e("September", "appointzilla"); ?>", "<?php _e("oktober", "appointzilla"); ?>", "<?php _e("November", "appointzilla"); ?>", "<?php _e("December", "appointzilla"); ?>" ],
    		monthNamesShort: ["<?php _e("Jan", "appointzilla"); ?>","<?php _e("Feb", "appointzilla"); ?>","<?php _e("Mar", "appointzilla"); ?>","<?php _e("Apr", "appointzilla"); ?>","<?php _e("May", "appointzilla"); ?>","<?php _e("Jun", "appointzilla"); ?>","<?php _e("Jul", "appointzilla"); ?>","<?php _e("Aug", "appointzilla"); ?>","<?php _e("Sept", "appointzilla"); ?>","<?php _e("Oct", "appointzilla"); ?>","<?php _e("nov", "appointzilla"); ?>","<?php _e("Dec", "appointzilla"); ?>"],
    		dayNames: ["<?php _e("s?ndag", "appointzilla"); ?>","<?php _e("m?ndag", "appointzilla"); ?>","<?php _e("tisdag", "appointzilla"); ?>","<?php _e("onsdag", "appointzilla"); ?>","<?php _e("torsdag", "appointzilla"); ?>","<?php _e("fredag", "appointzilla"); ?>","<?php _e("l?rdag", "appointzilla"); ?>"],
    		dayNamesShort: ["<?php _e("s?ndag", "appointzilla"); ?>","<?php _e("m?ndag", "appointzilla"); ?>", "<?php _e("tisdag", "appointzilla"); ?>", "<?php _e("onsdag", "appointzilla"); ?>", "<?php _e("torsdag", "appointzilla"); ?>", "<?php _e("fredag", "appointzilla"); ?>", "<?php _e("l?rdag", "appointzilla"); ?>"],
    		buttonText: {
    				today: "<?php _e("Idag", "appointzilla"); ?>",
    				day: "<?php _e("Dag", "appointzilla"); ?>",
    				week:"<?php _e("Vecka", "appointzilla"); ?>",
    				month:"<?php _e("M?nad", "appointzilla"); ?>"
    		},
    		selectable: true,
        		selectHelper: true,
    			select: function(start, end, allDay){ //alert("id="+serviceId);
    				/*jQuery('#bkbtndiv').show();
    				jQuery('#AppSecondModalDiv').show();
    				jQuery('#AppFirstModal').show();
    				jQuery('#AppFirstModalDiv').show();*/
    				//alert(end);
    
    		},
    			editable: true,
    		events: [
    <?php		//Loading Appointments On Calendar Start
    		global $wpdb;
    		$serviceId= $_POST['serviceId'];
    		<strong>if(isset($_POST['action']) == "getServiceid") {
    		    $serviceId= $_POST['serviceId'];</strong>
    		$AppointmentTableName = $wpdb->prefix."ap_appointments";
    		$FetchAllApps_sql = "select <code>name</code>, <code>start_time</code>, <code>end_time</code>, <code>date</code> FROM <code>$AppointmentTableName</code> WHERE service_id=<strong><code>$serviceId</code></strong>";
    Plugin Contributor FARAZFRANK

    (@farazfrank)

    Tell me exactly, What you want to do?

    Thread Starter Anand Kr mishra

    (@anand-kr-mishra)

    Hi Frank,
    I just wanted to use serviceId into query

    $FetchAllApps_sql = “select name, start_time, end_time, date FROM $AppointmentTableName WHERE service_id=$serviceId”;

    I am waiting for your response.

    Thanks,

    Anand

    Plugin Contributor FARAZFRANK

    (@farazfrank)

    Post Service Id via Ajax

    function PostserviceId() {
      var service_id = jQuery("#Service-Field-ID").val();
      Datastring = "action=sendserviceid&ServiceId=" + service_id ;
      var url = location.href;
      jQuery.ajax({
          dataType : 'html',
          type: 'POST',
          url : url,
          cache: false,
          data : Datastring,
          complete : function() {  },
          success: function(data) {
              alert('variable posted');
          }
      });
    }

    PHP Code to get ServiceId

    <?php
    if(isset($_POST['action']) == "sendserviceid") {
         $ServiceId = $_POST['ServiceId'];
         // now here use $ServiceId in query
    }
    ?>

    Thanks

    Thread Starter Anand Kr mishra

    (@anand-kr-mishra)

    Thanks for your help ,but i get blank $ServiceId in this code

    [ Moderator note: please wrap code in backticks or use the code button. ]

    if(isset($_POST['action']) == "sendserviceid") {
         $ServiceId = $_POST['ServiceId'];
         // now here use $ServiceId in query
    }

    whereas i send 18 in ajax.

    Plugin Contributor FARAZFRANK

    (@farazfrank)

    Check $_POST has any value or nothing

    <?php print_r($_POST); ?>

    Thread Starter Anand Kr mishra

    (@anand-kr-mishra)

    Hi Frank,
    Whatever i am printing into the following php code under event it is giving error:

    events: [

    [ Moderator note: please wrap code in backticks or use the code button. ]

    <?php		//Loading Appointments On Calendar Start
    		global $wpdb;
    		$AppointmentTableName = $wpdb->prefix."ap_appointments";
    		print_r($_POST);
    
    error(JS error console) is as follows:
    
    SyntaxError: missing ] after element list
    Source File: https://localhost/wordpress/?p=41
    Line: 188, Column: 4
    Source Code:
        {

    After clicking into it , it is shown as follows:

    editable: true,
    		events: [
    Array
    (
    )
    				{
    					title: "(08:00 - 10:00) Bokningsbara tider ",
    					start: new Date(2013, 9, 24, 08, 00),
    					end: new Date(2013, 9, 24, 10, 00),
    					allDay: false,
    					backgroundColor : "#1FCB4A",
    					//backgroundColor : "blue",
    					textColor: "black",
    				},

    Thread Starter Anand Kr mishra

    (@anand-kr-mishra)

    It’s really frustating…….

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Anand? You really need to start wrapping your code in backticks or just use the code button…

    Plugin Contributor FARAZFRANK

    (@farazfrank)

    Why you printing PHP code in JS code?

    Put print_r($_POST); in start of the file or end of the file.

    And after JS code run, check Console with Firebug Addon.

    Use Mozilla Firefox with firebug addon installed.

    Press F12, to check Console tab and output of your JS code.

    I can’t tell you all every things, you needs to basic knowledge of PHP, JS to performs modification in code.

    I know It’s frustrating.

    Thanks
    Frank

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Unable to use javascript in query’ is closed to new replies.