Jump to content

onclick fails to submit


totallytech

Recommended Posts

Hey,

 

I've got some code, which if autorefresh=1 then the submit button disappears and the page should change.

 

The button does indeed disappear, however the page no longer changes and I cannot see what I'm missing...

 

if ( $autorefresh ) {
			$script .= "$('.app_services_button').hide();";
		}
 
		$script .= "$('.app_select_services').change(function(){";
		$script .= "var selected_service=$('input[type=radio][name=app_select_services]:checked').val();";
		$script .= "if (typeof selected_service=='undefined' || selected_service===null){";
		$script .= "selected_service=".$appointments->get_first_service_id().";";
		$script .= "}";
		$script .= "$('.app_service_excerpt').hide();";
		$script .= "$('#app_service_excerpt_'+selected_service).show();";
		if ( $autorefresh ) {
			$script .= "window.location.href='".$href."'.replace(/__selected_service__/, selected_service);";
		}
		$script .= "});";
 
		$script .= "$('.app_services_button').click(function(){";
		$script .= "var selected_service=$('input[type=radio][name=app_select_services]:checked').val();";
		$script .= "window.location.href='".$href."'.replace(/__selected_service__/, selected_service);";
		$script .= "});";
There is also this code:

 

$(function () {
	$(document)
		.on("click", ".app_services_button, .app_workers_button", handle_submission)
		.on("click", ".appointments-list table td.free, .app_timetable div.free", handle_scheduling)
		.on("click", ".app_monthly_schedule_wrapper table td.free", handle_day_switch)
		.on("change", ".app_select_services", load_service_description)
		.on("change", ".app_select_workers", load_worker_biography)
	;
}); 
Can anyone see what I've missed?
Link to comment
Share on other sites

Any ideas why the location isnt working onclick?

 

I'm not sure if I've included enough code  - this is the whole function:

public function process_shortcode ($args=array(), $content='') {
		extract(wp_parse_args($args, $this->_defaults_to_args()));

		global $wpdb, $appointments;
		$appointments->get_lsw();

		if ( !trim( $order_by ) )
			$order_by = 'ID';

		if ( $worker ) {
			$services = $appointments->get_services_by_worker( $worker );
			// Find first service by this worker
			$fsby = $services[0]->ID;
			if ( $fsby && !@$_REQUEST['app_service_id'] ) {
				$_REQUEST['app_service_id'] = $fsby; // Set this as first service
				$appointments->get_lsw(); // Update
			}
			// Re-sort worker services
			if (!empty($services) && !empty($order_by) && 'ID' !== $order_by) $services = $this->_reorder_services($services, $order_by);
		}
		else
			$services = $appointments->get_services( $order_by );

		$services = apply_filters( 'app_services', $services );

		// If there are no workers do nothing
		if ( !$services || empty( $services ) )
			return;

		$script ='';
		$s = '';
		$e = '';

		$s .= '<div class="app_services">';
		$s .= '<div class="app_services_dropdown">';
		$s .= '<div class="app_services_dropdown_title">';
		$s .= $select;
		$s .= '</div>';
		$s .= '<div class="app_services_dropdown_select">';
		if ( $services ) {
			foreach ( $services as $service ) {
				$service_description = '';
				// Check if this is the first service, so it would be displayed by default
				if ( $service->ID == $appointments->service ) {
					$d = '';
					$sel = ' checked="checked"';
				}
				else {
					$d = ' style="display:none"';
					$sel = '';
				}
				// Add options
				$s .= '<input type="radio" name="app_select_services" id="'.$service->ID.'" value="'.$service->ID.'"'.$sel.' /><label for="'.$service->ID.'"><img src="http://mysite.co.uk/'.$service->ID.'.png" style="border:0;margin:0;"></label>';
				
				// Include excerpts
				$e .= '<div '.$d.' class="app_service_excerpt" id="app_service_excerpt_'.$service->ID.'" >';
				// Let addons modify service page
				$page = apply_filters( 'app_service_page', $service->page, $service->ID );
				switch ( $description ) {
					case 'none'		:		break;
					case 'excerpt'	:		$service_description .= $appointments->get_excerpt( $page, $thumb_size, $thumb_class, $service->ID ); break;
					case 'content'	:		$service_description .= $appointments->get_content( $page, $thumb_size, $thumb_class, $service->ID ); break;
					default			:		$service_description .= $appointments->get_excerpt( $page, $thumb_size, $thumb_class, $service->ID ); break;
				}
				$e .= apply_filters('app-services-service_description', $service_description, $service, $description) . '</div>';
			}
		}
		$s .= '<input type="button" class="app_services_button" value="'.$show.'">';
		$s .= '</div>';
		$s .= '</div>';

		$s .= '<div class="app_service_excerpts">';
		$s .= $e;
		$s .= '</div>';
		$s .= '</div>';
		if ( isset( $_GET['wcalendar'] ) && (int)$_GET['wcalendar'] )
			$wcalendar = (int)$_GET['wcalendar'];
		else
			$wcalendar = false;
		// First remove these parameters and add them again to make wcalendar appear before js variable
		$href = add_query_arg( array( "wcalendar"=>false, "app_provider_id" => false, "app_service_id" => false ) );
		$href = apply_filters( 'app_service_href', add_query_arg( array( "wcalendar"=>$wcalendar, "app_service_id" => "__selected_service__" ), $href ) );

		if ( $autorefresh ) {
			$script .= "$('.app_services_button').hide();";
		}

		$script .= "$('.app_select_services').change(function(){";
		$script .= "var selected_service=$('input[type=radio][name=app_select_services]:checked').val();";
		$script .= "if (typeof selected_service=='undefined' || selected_service===null){";
		$script .= "selected_service=".$appointments->get_first_service_id().";";
		$script .= "}";
		$script .= "$('.app_service_excerpt').hide();";
		$script .= "$('#app_service_excerpt_'+selected_service).show();";
		if ( $autorefresh ) {
			$script .= "window.location.href='".$href."'.replace(/__selected_service__/, selected_service);";
		}
		$script .= "});";

		$script .= "$('.app_services_button').click(function(){";
		$script .= "var selected_service=$('input[type=radio][name=app_select_services]:checked').val();";
		$script .= "window.location.href='".$href."'.replace(/__selected_service__/, selected_service);";
		$script .= "});";

		if (!$_noscript) $appointments->add2footer( $script );

		return $s;
	}
Edited by totallytech
Link to comment
Share on other sites

I've had a little edit as I found some code that creates a click function on each img with a class thumbnail, so I've added the class to the images.

 

This is the code

 

$script .="$(document).ready(function() {";
$script .="$('img.thumbnail').click(function() {";
$script .="window.location.href='".$href."'.replace(/__selected_service__/, selected_service);";
$script .="});";
$script .="});";
				
$s .= '<input type="radio" name="app_select_services" id="'.$service->ID.'" value="'.$service->ID.'"'.$sel.' /><label for="'.$service->ID.'"><img class="thumbnail" src="http://kerrymotorservices.co.uk/wp-content/uploads/2015/04/'.$service->ID.'.png" title="'.$service_description.'"></label>';
However it still doesnt work. Any ideas what I've missed? Edited by totallytech
Link to comment
Share on other sites

There are a lot of possible places this is going wrong - from putting the code in the wrong file to never queuing it in your WordPress theme to never actually outputting the built strings.

 

Are you using a theme you bought/downloaded, are you creating a theme yourself, where is the listed code found (what files, where are they located, etc.), what relevant code is in the functions file, and so on. Giving us a fuller picture might help point someone in the right direction to help.

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.