Code Samples

I have used several different programming languages for both front end and back end development. Here are some of the more interesting samples:

JQuery to control a shopping cart

The code below is used on the shopping cart page at My Shoe Connection. It allows the user to control quantity by either clicking on the "+" or "-" to add or subtract the quantity for an item they added to their shopping cart. If the quantity goes below one, the item is removed from the cart. You can see this code in action by going to www.myshoeconnection.com, adding an item to the shopping cart and then clicking on the shopping cart. Ajax is used to call classic asp programs to update the session variable.

$(document).ready(function() {
	$('.cart_item').find('#delete_item').click(function(){
		remove_item($(this).attr('rel'),'delete');
		$(this).parent('.prod_image').parent('.cart_item').hide();
		recalc_order();
	});

	$('.sub1').click(function(){
		cart_item=$(this).parent('.col-12').parent('.prod_name').parent('.cart_item');
		lineItem=$(this).parent('.col-12').parent('.prod_name').attr('rel');
		action='qty';
		numberOfUnits=cart_item.find('#txt_units').val();
		numberOfUnits=(numberOfUnits*1)-1;
		cart_item.find('#txt_units').val(numberOfUnits);

			if (numberOfUnits==0){
			removeMe=cart_item.find('#delete_item').attr('rel');
			remove_item(removeMe,'delete');
			cart_item.find('#delete_item').parent('.prod_image').parent('.cart_item').hide();
			}

		updateUnits(lineItem, action, numberOfUnits);

		line_value=numberOfUnits * cart_item.find('.prod_price').attr('rel');
		cart_item.find('.prod_price').find('#line_total').html(line_value.toFixed(2) );

	});

	$('.add1').click(function(){
		cart_item=$(this).parent('.col-12').parent('.prod_name').parent('.cart_item');
		lineItem=$(this).parent('.col-12').parent('.prod_name').attr('rel');
		action='qty';
		numberOfUnits=cart_item.find('#txt_units').val();
		numberOfUnits=(numberOfUnits*1)+1;
		cart_item.find('#txt_units').val(numberOfUnits);
		updateUnits(lineItem, action, numberOfUnits);
		line_value=numberOfUnits * cart_item.find('.prod_price').attr('rel');
		cart_item.find('.prod_price').find('#line_total').html(line_value.toFixed(2) );

	});

	$('#txt_units').keyup(function(){
		cart_item=$(this).parent('.col-12').parent('.prod_name').parent('.cart_item');
		lineItem=$(this).parent('.prod_units').parent('.col-12').parent('.prod_name').attr('rel');
		action='qty';
		numberOfUnits=$(this).val();
		updateUnits(lineItem, action, numberOfUnits);

		line_value=numberOfUnits * cart_item.find('.prod_price').attr('rel');
		cart_item.find('.prod_price').find('#line_total').html(line_value.toFixed(2) );
		alert(cart_item.attr('rel'));
	});

	$('.go_button').click(function(){
		$('#cartAdd').action= "chkmember.asp";
		$('#cartAdd').submit();
	});
});

function remove_item(lineItem, action){

  navString='?line_item=' + lineItem + '&actionD='+ action;

	jqxhr = $.post('yourcart2.asp' + navString, function(data){
		$('.user_options').find('.shopping_cart').html(data);
		});

		jqxhr.success(function() {

		});

		jqxhr.error(function() {
		$('#cart_contents').html(navString);

		});

		jqxhr.complete(function() {
		});
}

function updateUnits(lineItem, action, units){

  navString='yourcart2.asp?line_item=' + lineItem + '&actionD='+ action +'&units='+units;

 var data;
	$.ajax({
		url: navString,
		data: data,
		async: false,

		success: function (data) {
		$('.user_options').find('.shopping_cart').html(data);
		recalc_order();

		},

		error: function () {}

	});

}

function recalc_order(){
	navString='yourcart2.asp?actionD=recalc';
	var data;

	$.ajax({
		url: navString,
		data: data,
		async: false,

		success: function (data) {
			$('.subtotal').html(data.toString());

			if($('.sub_value').attr('rel')<=0){
				$('.go_button').hide();
				$('#cart_instructions').hide();
				$('.subtotal').html("Your Cart Is Empty");
				$('.user_options').find('.shopping_cart').html("");
			}

		},

		error: function (data) {
		$('.subtotal').html(data);
		}

	});

}
				
PHP to render a sitemap

The code below is used on this site and other sites to render a sitemap or create navigation on the top of the pages. Making use of the SimpleXMLElement() and some nested for loops, it is a very easy script.

			
			<?php
			global $gAudience;
			$gSitemap = new SimpleXMLElement($_SERVER['DOCUMENT_ROOT']."\\inc\sitemap.xml",0,true);
			$gAudience = $gSitemap->xpath("audience[@type='worker']/page");
			$gPage = $gSitemap->xpath("audience[@type='worker']//page[@href='".$gScriptName."']");
			$gPage = $gPage[0];
			$blnNotFirstPage = false;

			foreach( $gAudience as $page ) {
				if( $page["sitemap"] == "true" ) {

					$strProtocol = "http://";
						if ( $page["ssl"] == "true" ) {
						$strProtocol = $gSSLProtocol;
						}

					$strClass = "";
					if( $page["href"] == $gScriptName ) {
						$strClass .= " current";
					}


					$blnNotFirstPage = true;
					$children = $page->children();

					$blnShowChildren = false;

					foreach( $children as $child ) {
						if( $child["sitemap"] == "true" ) {
							$blnShowChildren = true;
						}
					}

					if( $blnShowChildren ) {
					?>

					
  • <?php echo $page["title"]; ?>
      <?php foreach( $children as $child ) { if( $child["sitemap"] == "true" ) { $strProtocol = "http://"; if ( $page["ssl"] == "true" ) { $strProtocol = $gSSLProtocol; } ?>
    • <?php echo $child["title"]; ?>
    • <?php } } ?>
  • <?php }else{ ?>
  • "><?php echo $page["title"]; ?>
  • <?php } } }