Archive for the ‘JavaScript/Ajax’ Category

Recently at my job, I had to setup Bronto email tracking pixels on our order confirmation page. The tracking pixels came in the form of an image tag and had to be populated with some values from our shopping cart. The values (invoice number and order amount) are passed from the order confirmation page using hidden fields.

<input name="InvID" type="hidden" id="InvID" value="12345" />
<input name="Tot" type="hidden" id="Tot" value="69.9900" />

I then used JavaScript to extract the values in the hidden inputs and assigned them variables.

var InvoID = document.getElementById("InvID").value;
var SubTotal = document.getElementById("Tot").value;

Then, I used document.write to create an image tag on the fly with the correct values filled out using JavaScript concatenation.

document.write("<img src='http://bronto.com?type=$&description="+InvItemName+"&money="+ItemPrice+">'");

I have recently found that if you have apostrophes in your code, it will break the above tracking script. A way around this would be to use a string replace function like this:

InvItemName.replace(/'/i,"")

*NOTICE: The values in the scripts are dummy values, as I had to hide some confidential account data. The code is just to show as an example, but its pretty easy to setup. You can use similar techniques to setup Google, MSN, Yahoo, and other types of tracking pixels.

I recently ran into an issue at work where we have been spending countless hours making 6 and 12 bottle shots by hand in Photoshop. We would take one bottle and copy/clone it over 6 or 12 times, then save and resize the image for the web. It became so repetitive that I created a little script that would do the same thing, but only using one image and some fancy jQuery.

Here is my script:

JavaScript and jQuery

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
 
    <script type="text/javascript">
 
        $(document).ready(function() {
 
        	//12 bottles - 486w - 40.5/bottle
        	//6 bottles - 486w - 81/bottle
        	var bottles = 12;
 
        	if (bottles == 12) {
        		alert("12 bottles");
        		for (i = 0 ;i < 12;i++)
            	{
            		$(".image-container").append("<div class='bot12'><img src='http://4seasonswine.com/labels/small/0109107.jpg' class='bottle'></div>");
            		//console.log("bottle"+i);
            	}
        	}
 
        	else if (bottles == 6) {
        		alert("6 bottles");
        		for (i = 0 ;i < 6;i++)
            	{
            		$(".image-container").append("<div class='bot6'><img src='http://4seasonswine.com/labels/small/0109107.jpg' class='bottle'></div>");
            		// for firebug console.log("bottle"+i);
            	}
        	}
 
        });
    </script>

CSS to float the images left:

    <style>
        .bot6 {
            float:left;
            width:81px;
        }
 
        .bot6 img {
            width:81px;
        }
 
        .bot12 {
            float:left;
            width:38px;
        }
 
        .bot12 img {
            width:40.5px;
        }
    </style>

HTML to display the images:

<body>
	<div class="image-container"></div>
 
</body>

See it in action:
jQuery Bottle Clone Example

JS Conf 2009

Last weekend I attended JS Conf 2009 in Washington D.C. with a good friend of mine, we actually brought our wives too. The plan was to attend the conference while our wives saw the sites and toured the town. We couldnt have asked for better weather, all 3 days the temperatures were 80-90 and not a cloud in the sky.

The JS Conference itself was pretty awesome, I have never been to a web conference before so I dont have much to compare it with. It was a small conference of about 150 people, but all the rockstars were there including John Resig, Jeff Haynie, and Richard D. Worth among many others I was less familiar with. It being the first year of the conference, I wasnt quite sure how it would go down – but my friend and I were pleasantly surprised with how smooth it went. All the speakers did a bang up job, the sessions were about an hour each – which was the perfect amount of time.

Overall, I wish there were more hands-on type of sessions – a few sessions were pretty basic, but then there were a few that were really advanced – it was a nice mix. I’m still somewhat a newbie at OOP JavaScript, so it would have been neat to get a quick-paced session on best practices for OOP/JS. There were also smaller ad-hoc sessions that anyone could volunteer for day-of. The conf really opened my mind up to how much JavaScript it become a huge part of web and how a new sub-culture of developers is emerging.

There are rumors that JS Conf 2010 will be in NYC, if thats the case I will definitely go again! Although being in DC was fantastic, such an amazing city.

A few months ago, I created a little script using the jQuery library which will add class=”current” to tabs, allowing you to highlight your menu for you users. Its pretty basic, but it searches the URL, if it finds a match with the link that was clicked – then it add’s class=”current” to that particular tab. You can then use that class in your css, to make a highlighted state.

Here is the code:

 
// Highlight Tab v.01 by Jake Rutter
// Website: http://www.onerutter.com
// Feel free to use and adapt, please just give credit where credit is due.
 
// ----------- highlight tab function -----------
    var path = location.pathname;   
 
    var home = "/";
    $("a[href='" + [ path ] + "']").parents("li").each(function() { 
        $(this).addClass("selected");
    });

Feel free to adapt and use this code on your site, I would appreciate it if you could leave my comments in as the creator in the .js file. If you are unfamiliar with how jQuery works, you can read this tutorial which will get you up to speed!

jQuery Highlight Script (812)

Yesterday, I received an email from Appcelerator, informing me of a new product of theirs called Titanium. Appcelerator Titanium is an open source RIA platform for developer desktop web apps, similar to the Adobe AIR platform, in that it uses standard, common web languages such as html, css, and javascript. That is what caught my eye, as I’ve read a few books on flex and messed around a bit, but I already know the ins and outs of html/css/javascript. Thats my everyday toolkit for building websites and user interfaces. I ventured onto their website, and watched a few screencasts and then downloaded the demos, which included a twitter and youtube demo.

After checking out the demos sourcecode, I was pretty damn impressed. I thought to myself, “What’s next? How do I start? “. I found the SDK, but just the word SDK can be a little daunting for a web developer, I like to think of it as more of a WDK or Web Development Kit. So I downloaded it, installed it, and followed a screencast from their website to generate my first app. It took about 20 min from start to finish, and Voila! I had a sample app running from an installer. Amazing!

My past experience with Ruby on Rails also helped, as the setup of the app is very similar to that of a ruby on rails project. The terminal commands were easy, and the ability to create installers for OSX, Windows, and Linux were kickass! The documentation was also excellent for such an early release, I only ran into one bug on windows, but I think it had to do with Chrome support for my code, so it could have been a self-inflicted bug and not a Titanium bug.

One of the most desirable things about Titanium is that it has the jQuery library built-in, AWESOME! So I decided to dedicate 2 hrs to messing around in Titanium to see just how far I could get. Well, in 2 hrs I built a little desktop app that allows you to play 6 videos through a custom flash player that are streamed from the web. I basically re-used code from another project that utilized flash, jQuery, and html/css to see if it would work and how fast I could get something up and running. Its not anything I would release to the world, but it really opened my eyes up to how fast I could get something done and the possibilities that Titanium have opened for me.

I’m ready to sell my books on Flex, remove Flex builder from my desktop and go all out on Titanium. What does Flex give me that Titanium doesn’t, and if there is something – then Im sure the guys at Appcelerator will be adding soon enough, as this is just a Preview Release.

So if you haven’t yet checked out Appcelerator Titanium, I highly encourage you to do so.

Thank you Appcelerator!

Also, today someone posted great article on The similarities/differences of Appcelerator Titanium and Adobe AIR

Google Maps API for Flash

Just as Yahoo! created an API for Flash a few months ago, Google has followed and created one too. Im looking forward to playing around with this one, I have already messed around with the Yahoo! api. Yahoo! has done a great job of including well defined documentation.

http://code.google.com/apis/maps/documentation/flash/

I had to build a dynamic promo box that would show/hide layers depending on which promo code was entered in the box. I searched high and wide on google for a tutorial that would show me how to achieve this, after no such luck I built it myself. I decided I might as well post this code, which might in turn help someone else.

function validate() {
if ((document.promoCode.Specify.value == "promo1" )){
document.getElementById("promo1").style.display = "block";
document.getElementById("promo2").style.display = "none";
document.getElementById("promo3").style.display = "none";
document.getElementById("error").style.display = "none";
//return false;

} else if ((document.promoCode.Specify.value == "promo2" )){
document.getElementById("promo1").style.display = "none";
document.getElementById("promo2").style.display = "block";
document.getElementById("promo3").style.display = "none";
//return false;

} else if ((document.promoCode.Specify.value == "promo3" )){
document.getElementById("promo1").style.display = "none";
document.getElementById("promo2").style.display = "none";
document.getElementById("promo3").style.display = "block";
//return false;

} else {
document.getElementById("error").style.display = "block";
document.getElementById("promo1").style.display = "none";
document.getElementById("promo2").style.display = "none";
document.getElementById("promo3").style.display = "none";
//return false;
}

//return true;
}


next door movie girl themovies cunt gushingtrailers lesbian moviemovies cock massiveadult movie quicktime clipsmovies oralpam tommy movie lee andersonmovies fuck perfectscenes in rape moviesmovie theaters raveanimal amateur porn3d video porn75 sex tipsfree porn 100 picssex pics adult moviesteens about19 teen101teen Mapporno mongoes captin playhousepornography capturingcar mpgs pornpornos caramelstar caramel the porncaptors card pornporn carebearporn carey Mapnipples swollenporn dirtylarge dickssimpsons nudesucking penislady godivabeautiful buttsgirls hogtied Mapgallery miniskirtpreteen undergroundnaked cartoonsstripping menskirts poodlebiker chickvideos handjobmilitary sex Map

Ajax Scripts

As Ajax has been gaining ground in the web world, I have been taking a closer look. I found this site that has a nice little and easy to understand tutorial on how to implement a simple to-do list.AJAX To-Do List Tutorial

|