javascript - Simple onclick fails to redirect url -
i'm looking help.
i've got should simple onclick redirect on image.
i found code (shown below) assigns onclick function every image uses class thumbnails. reason not allowing url redirect. no js errors pop failing...
$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>';
can please?
firstly use $href
before defining (in pastebin posted define $href 50 lines later). either move bit of code after, or define $href earlier.
secondly, in button you're defining variable selected_service
you're not doing in click
thumbnail img. add following line first line in click
function, should like:
$script .= "<script>$(document).ready(function() {"; $script .= "$('img.thumbnail').click(function() {"; $script .= "var selected_service=$('input[type=radio][name=app_select_services]:checked').val();"; //...
edit:
alright changed added line little bit:
$script .= "var selected_service=$(this).parent().prev('input[type=radio][name=app_select_services]').val();";
Comments
Post a Comment