Archive for March, 2007

  • 25
  • Mar

Amazon is usually known for reasonably priced books or CDs, but some of the other high-priced items they carry may surprise you. :)

I stumbled across this site recently which has a large list of any and all high-priced items on Amazon, but in this post I’m only highlighting the ones I found particularly interesting.

How would you like to own your own, personal space suit for only a million dollars? Of course, if you got that, you’d also need your own $10 million space ship. With those you can bring back a $1 million space rock paperweight… a great addition to any office!

Read the reviews on the space rock, they’re pretty good. :)

People say BMWs have expensive parts (I drive an M3), but at least I don’t drive a Civic! They have to pay almost $900,000 for an aftermarket exhaust.

And I know Amazon sells a lot of random things like some auto parts (above)… but a full auto parts store?

If your a chemistry geek, Amazon has a great deal on a magazine subscription… only $6,000 per issue!

And of course, for the lady…. Amazon sells a certified, 7.12 carot, half-million dollar diamond.

  • 24
  • Mar

I’ve gotten quite a few comments on my recent post about creating a sliding, collapsible DIV, and while I like to leave some things unsaid, to be figured out by the reader… one question that repeated kept coming up was how to toggle the sliding with a single button/link.

This is a quite simple process. Let’s assume we have all the code already in place from the last tutorial. In your motionpack.js file, let’s add a new function at the very bottom, looking like this:

function toggleSlide(objname){
  if(document.getElementById(objname).style.display == "none"){
    // div is hidden, so let's slide down
    slidedown(objname);
  }else{
    // div is not hidden, so slide up
    slideup(objname);
  }
}

Now, stepping though this function is very simple. There’s an if-statement to check is the DIV is already hidden, or if it’s still visible. If the style.display property is set to “none”, then it’s hidden, so we slide the DIV down. If it is visible, the code jumps to the else statement, and slides the DIV up, using the same slidedown() and slideup() functions we used in the last tutorial.

Now, your link itself would look like this:

<a href="javascript:;" onmousedown="toggleSlide('mydiv');">Toggle DIV Slide</a>

This is assuming your DIV still has the ID of ‘mydiv’.

And finally, here is the new code in action:


Toggle DIV Slide

Enjoy! And also, I’m always listening for new ideas for tutorials. If there’s something you’d like me to explain, ask! :)

  • 20
  • Mar

This is what happens when geeks have too much free time.

I’m ashamed at laughing at this. :)

Another, even more geeky one, can be found here:
L33t Haxxors

  • 18
  • Mar

On the heels of two very successful tutorials on creating a collapsible div and an animated sliding div, I’ve decided to write another. It seems my last few helped a number of programmers learn a simple trick, and hopefully this one will do the same.

Note, I’ve also upgraded to a much newer, faster server, so hopefully the social networking sites won’t “collapse my server” again, as one Digger so eloquently put it. :)

Hearing about AJAX constantly, but never have found time to read a lengthy, frustrating, complex tutorial? In the following post, I’m going to explain how to add AJAX functionality to your website in three easy steps. It’s actually quite simple, and I’m going to try and be clear and to the point, but not over or under-explain anything like most tutorials have a tendency to do.

Before you begin, decide what purpose or additional functionality adding AJAX to your website will accomplish. Will it be a live search feature? Something to save user preferences? In this example, we’re developing a simple calculator. Let’s dive in.

Step 1: Create the Intelligence
First let’s make the brain of the system. In our calculator, we’re going to need a PHP function to actually perform the operations. We’ll handle the front-end later, but for this file, we’ll take our input from GET request strings (variables passed through the URL itself, such as file.php?var=value&var2=test).

Name this file: backend.php
<?
  if($_GET['op']=="" || $_GET['num1']=="" || $_GET['num2']==""){
    echo "Error: Please complete all fields.";
    exit;
  }
 
  if($_GET['op'] == "divide" && $_GET['num2'] == "0"){
    echo "Error: Division by zero.";
    exit;
  }
 
  if(!is_numeric($_GET['num1']) || !is_numeric($_GET['num2'])){
    echo "Error: Invalid numbers.";
    exit;
  }
 
 
  switch($_GET['op']){
    case "add":
      echo $_GET['num1'] + $_GET['num2'];
      break;
    case "subtract":
      echo $_GET['num1'] - $_GET['num2'];
      break;
    case "multiply":
      echo $_GET['num1'] * $_GET['num2'];
      break;
    case "divide":
      echo $_GET['num1'] / $_GET['num2'];
      break;
  }
?>

Now, let’s take a look at this file. We’re working with three variables passed from the GET string: the operation such as add/subtract/divide/multiple ($_GET['op']), and the two numbers we’re performing the math on ($_GET['num1'] and $_GET['num2']). For example, we might call this page like this: backend.php?op=add&num1=12&num2=4 . This is running our above file (backend.php), passing “add” as the ‘op’ variable, and 12 and 4 as the two numbers.

The first four lines of the above backend.php script checks to make sure all the variables were entered. If any of the three values are blank (“”), then it errors and exits. The next if-block is checking for a divide by zero error. If the op variable is divide and the num2 variable is zero, it errors and exits. Simple.

Next it checks to ensure you entered valid numbers with the is_numeric() function in PHP. If you enter a letter or something else in the field, it will show and error and exit.

The next (and last) block we get to is the switch statement. This goes through and checks the op variable to see what we’re trying to do here. Every case-statement represents one of the possible operations (add/subtract/divide/multiply). When it figures out which operation is being requested, it performs the math on num1 and num2, echo’s the result, and breaks out of the switch statement, thus ending the file. If you need to brushen up on how switch statements work, php.net has a great tutorial.

There, now you’re 1/3rd done with adding interactive AJAX functionality to your web application. Easy right?

Step 2: Create the Form
Now we’re going to create the frontend to the AJAX. This is the part the user sees, and is mostly basic HTML. You can add this to any PHP or HTML file you have, anywhere you want.

Here’s the frontend code for our calculator:
<input type="text" id="num1" size="6">
<select id="op">
<option value="add">+</option>
<option value="subtract">-</option>
<option value="multiply">*</option>
<option value="divide">/</option>
</select>
<input type="text" id="num2" size="6">
<input type="button" value=" = " onClick="doMath();">
<div id="answer" style="display: inline; font-size: 16px"></div>

This is simple HTML, adding two textboxes, a drop-down (with values corresponding to the values of the case statement in backend.php), a button, and a DIV. Notice I’m not using a submit button (it doesn’t matter) because I’m not using a form. This might not be best practice, but it goes to show you’re not submitting anything to another page, like you traditionally would. The button has a function “doMath()” which is called from the onClick attribute. We’ll explain this function in step 3, but for now, just know that begins the AJAX and solves the math problem. Also notice we’re using id’s instead of names for the textboxes and drop-down field (select)- this is for us to reference the fields from Javascript in the next step. The last line is a simple DIV with a bit of CSS styling (display: inline makes it appear after the equals button, rather than on it’s own line, and the font size is for aesthetics). We set the id of this div to “answer”, and we’ll be using it later from the Javascript to output the answer.

Very easy. Now we have the backend setup to do the math, and the frontend to ask the user what kind of math he wants to do… so now the only piece left is connecting them together!

Step 3: Connecting the Frontend and Backend Together
This step is the trickiest, but stick with me, and you’ll see how easy it really is. We use Javascript (AJAX = Asynchronous Javascript and XML) to talk between the HTML and the PHP.

For this step, let’s create another new file, and call it ajax.js.

http = getHTTPObject();
 
function getHTTPObject(){
  var xmlhttp;
 
  /*@cc_on
 
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }catch(e){
      try{
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }catch(E){
      xmlhttp = false;
    }
  }
  @else
    xmlhttp = false;
  @end @*/
 
  if(!xmlhttp && typeof XMLHttpRequest != 'undefined'){
    try {
      xmlhttp = new XMLHttpRequest();
    }catch(e){
      xmlhttp = false;
    }
  }
 
  return xmlhttp;
}
 
function doMath(){
  var url = "backend.php?op=" + document.getElementById('op').value;
  url += "&num1=" + document.getElementById('num1').value;
  url += "&num2=" + document.getElementById('num2').value;
 
  http.open("GET", url, true);
  http.onreadystatechange = handleHttpResponse;
 
  http.send(null);
}
 
function handleHttpResponse(){
  if(http.readyState == 4){
    document.getElementById('answer').innerHTML = http.responseText;
  }
}

Now, your first reaction might be to panic, but stay calm, it’s not that bad. The entire getHTTPObject() function (half the file) you do not need to understand. It’s a standard function included in almost every AJAX script out there… simply copy and past that exactly as it is, and forget about it. There, now you’re just left with the first line, the doMath() function, and a small function called handleHttpResponse.

The first line is declaring an object to ask PHP for it’s result. Think of it as a mini web browser.

The doMath() function is where you actually send the AJAX request. Remember it being called when you click that button in the frontend? This is what’s run. The first three lines of this function are building a variable (url) that is the PHP page we’re going to request. It begins with “backend.php?op=” and grabs the value of the drop-down from the frontend to find out if we’re adding, subtracting, multiplying, or dividing. Then it adds the two numbers from the frontend on to the end of URL request string as well, using document.getElementById to find them (the textboxes’ values). Now the url variable is left with something similar to the example I gave right after the code in step 1. You could in theory plug this URL into your web browser, and see the result yourself, but instead we’ll let Javascript do it for us. The last three lines of the doMath() function pass that URL to our mini web browser (variable “http”), and essentially press the Go button. It sends the request, and tells it to notify us when it gets a response back, via the handleHttpResponse() function.

Now, the last function of our Javascript file is the handleHttpResponse() function… called automatically by our mini web browser when our PHP page finishes downloading (and it has an answer). The if-statement is basically saying “if the PHP site is done loading and you have an answer, continue.” The middle line is a call to set the innerHTML property of the answer DIV on the frontend to whatever the PHP page says…. in our case… the math answer.

Important!
Now, for this to work, you need to call the ajax.js file from the file where your frontend is. This is done by simply placing this line above the frontend somewhere in the code:
<script language="javascript" src="ajax.js"></script>
The best place to put this is between the HEAD tags of the file, but anywhere would work. If you do not add this line, your website will give errors when someone tries the AJAX, and it won’t work.

And you’re done!

Now, I’m sure critics are going to ask why do this with AJAX when I could easily accomplish the same thing with pure Javascript, and the answer is this is a tutorial to learn. Often times the PHP backend does MySQL calls, or things that Javascript couldn’t do. For example, live searches (results below the textbox as you type) are this same basic framework, but the backend searches a database for what the user is typing, and returns the results to set in the answer div (equivalent). Simple! :)

And as always, here is a live, working demonstration of the tutorial in action:

I enjoy your comments and requests for future tutorials!

  • 17
  • Mar

Have you ever seen one of those sci-fi movies where astronauts land on a distant, barren planet with blasts of acidic wind screaming across the desolate landscape, and a ground made from shards of ice and rock? Yeah… welcome to Digg. If you think you’re brave enough to register… first read through from our advice on how to survive among the masses.

11. Throw away your sympathy card
Diggers are (by nature) cold-blooded, heartless, soulless creatures with no morals. If you want some e-hugs for losing your goldfish, reconsider your membership.

10. Learn to hate Microsoft
Remember when you were six years old and fell off your bike? It is Microsoft’s fault. Didn’t like your dinner last night? Blame Microsoft. Got herpes? Microsoft. Simple.

9. God is a figment of your imagination
The Digg userbase is predominately Atheist. Whenever Richard Dawkins sneezes, there’s a front page article about it. On Digg, evolution is not a theory, it’s a historical fact.

8. Long lists suck
The average digger has an attention span on par with an African Fruit Fly. If you see any list with over 20 items, it’s your obligation as a Digger to skip it without a Digg.

7. Don’t burn bridges
Unnecessarily calling out other diggers is a quick way to get blacklisted. Use your friends list on Digg to build a positive network, which is very beneficial when submitting articles.

6. Learn your meme’s
O rly? But does Chuck Norris blend in your base setting a trap that runs linux? Lollerskates!!

5. Thou shalt only speak praise of Ubuntu
“Have you lost weight? Haircut? Oh, no, you just installed Ubuntu on your laptop. Nice!” Ubuntu Linux is in, and if you don’t know about it, you’re not.

4. Forget your business classes
Digg users like fighting cell phone contracts, protesting lawsuits, abusing copyrights, and just about anything else to make a stand against corporate dominance.

3. Train your stomach
What a normal person would consider vile and disgusting, diggers bask in. For example, a top story might be about male bodily fluids in aMcDonalds milkshake (link).

2. George Bush is always wrong
If unsure about touchy political debates on digg, always default to Bush is wrong. He says send in more troops to Iraq? Your hero is whoever says to withdrawal from Iraq.

1. There is no website better than Digg
People say Apple has a cult-like following… I believe digg is worse. There is a huge population of diggers who are beyond dedicated, even going as far as vandalizing other sites that use similar technology.

There you have it. Study these simple bullet points and you’ll make it just fine on Digg.

Digg on!

  • 06
  • Mar

Well, my last tutorial post about creating a collapsible div (no animation) was a huge hit, receiving over 1100 diggs.

I actually learned quite a bit from the comments. First of all, I implemented the wp-cache 2.0 so my server doesn’t go down after 70-100 diggs again, haha. Secondly, I found people wanted animation… Digg comment style sliding. I can do that. :)

So, expanding on the last tutorial, I’ve coded a small Javascript library that will allow that functionality. It’s not meant to be a mootools or a script.aculo.us replacement… those are far more advanced libraries. This is just a simple, quick bit of code you can apply to your websites to improve the user experience a bit.

In this tutorial, we will create functions to slide DIVs up and down. It supports multiple animations happening simultaneously, as well as a variable animation length. It’s also time-based, rather than increment based, so it’ll animate the same speed on most computers; old computers won’t take 10 minutes for a DIV to slide down.

Click here to see the final product.

First, create a new file on your webserver called motionpack.js – this is where we will store all the javascript functions for the animations, rather than cluttering up the top of the webpage itself, and slowing down it’s load time. In the beginning of that file, let’s first declare some initial variables:
var timerlen = 5;
var slideAniLen = 500;
These are the variables you will change if you want to tweak the speed of the animation on your site. timerlen is how often the Javascript function will run to alter the DIV’s properties (altering height or opacity)… it’s probably best to leave this at 5. Any lower will be slightly smoother, but will require your visitors have a better computer (otherwise it’ll be choppy), and much higher will be choppy on everyone, because it’s not updating enough to look smooth. The next variable, slideAniLen, is how long it should take a DIV to completely slide up or completely slide down. This is in milliseconds, so setting it to 500 means it’ll take half a second to complete the animation effect. This is fairly quick, so some people might want to increase and make it a bit slower.

Now, the next part of the JS file:
var timerID = new Array();
var startTime = new Array();
var obj = new Array();
var endHeight = new Array();
var moving = new Array();
var dir = new Array();
These are some variables we’ll use throughout the code below to keep track of our animations. We use arrays for each object to allow multiple animations to happen simultaneously. We’ll explain where each of these are used later on, but for now, simply paste them into your JS file.

Now we’re getting to the actual functions. These first functions are what we call from our website itself. They essentially serve as the API for this mini-library.
function slidedown(objname){
  if(moving[objname])
    return;
 
  if(document.getElementById(objname).style.display != "none")
    return; // cannot slide down something that is already visible
 
  moving[objname] = true;
  dir[objname] = "down";
  startslide(objname);
}
 
function slideup(objname){
  if(moving[objname])
    return;
 
  if(document.getElementById(objname).style.display == "none")
    return; // cannot slide up something that is already hidden
 
  moving[objname] = true;
  dir[objname] = "up";
  startslide(objname);
}
This code adds the functions to call when requesting a DIV start sliding up or down. Let’s first look at the slideup() function. We pass it a single parameter- the DIV’s id (objname). The first line checks if the moving variable is set to true for that DIV, so we don’t begin animation on one that’s already moving. Once an animation starts, it will finish uninterrupted. If it is moving, on line 3, we return (exit from the function) so no further animation begins. The next line is a sanity checking if-statement. This function is beginning the slide down process of a DIV, and if a DIV’s display attribute is not set to none (not visible), we assume it’s already slid down and visible, so we can exit the function (abort the process), since there’s nothing else for us to do here. If those checks complete without any complications, we’re now ready to begin the sliding process, so we set the moving variable to true (so no other animation can start until we’re done), we set the direction variable to down (so it knows which way to move), and we call the function startslide(), which we’ll get to in a moment. The slideup() function is very similar, except it checks on the 3rd line inside that function to ensure the display property is not set to “none”, so the DIV is not visible, otherwise we have nothing to slide up, and we can abort the start slide process.

Now, I hope you guys are hanging in there, we’re almost through the tricky parts. :)

The next function we’ll throw in the file is the startslide() function mentioned above:
function startslide(objname){
  obj[objname] = document.getElementById(objname);
 
  endHeight[objname] = parseInt(obj[objname].style.height);
  startTime[objname] = (new Date()).getTime();
 
  if(dir[objname] == "down"){
    obj[objname].style.height = "1px";
  }
 
  obj[objname].style.display = "block";
 
  timerID[objname] = setInterval('slidetick('' + objname + '');',timerlen);
}
Okay, the last two functions were for making sure we really want to start the slide, and doing all the initial preparations. This function, startslide(), is where we actually begin the sliding process. We, as always, pass the DIV’s id (objname) that we’re working with as the function’s parameter. On the first line of this function, we set it in the obj[] array, so we can keep track of the id throughout the animation process. The next two lines set the endHeight to the original height (so we know where to start sliding from, or how far down to slide to), and the startTime, so we can keep track of how long this animation has been going on. Following this we have a nice three line if-statement that checks if we’re sliding down, and if we are, resizes the DIV’s height to 1px… a starting point to slide down from. Next it sets the object’s display attribute to “block”, making it visible (redundant if sliding up, but a good just-in-case measure never-the-less). Note: You might want to use “inline” instead of “block”, depending on your circumstances (inline will allow the DIV to have other content to the left and right of it, rather than adding a line break before and after it like block does), just be aware to change the other occurrences of “block” to “inline” if you do this. Finally the last line of the function is where we’ve set the initial timer, which will call the sliding function ever few milliseconds (depending on your settings of timerlen up top), and actually perform the animation itself.

Now, the function the above timer called was slidetick(), which is the next part of our motionpack.js file.
function slidetick(objname){
  var elapsed = (new Date()).getTime() - startTime[objname];
 
  if (elapsed > slideAniLen)
    endSlide(objname)
  else {
    var d =Math.round(elapsed / slideAniLen * endHeight[objname]);
    if(dir[objname] == "up")
      d = endHeight[objname] - d;
 
    obj[objname].style.height = d + "px";
  }
 
  return;
}
This function is what actually does the animation itself. The first line checks how long the animation has been in progress, by subtracting the animation’s start time from the current time. There’s then an if-statement that checks if the animation has exceeded the preset time (at the top of this file) for an animation’s length, and if so, it calls the endSlide() function, which cleans up (discussed below). If the elapsed time is not greater than the max time (the else-statement), it calculates the variable “d”. This calculation takes the ratio of time that’s progressed so far in the animation, and multiplies it by the final height of the DIV, so if half the time has progressed, for example, the variable d will contain half the height. Then it checks the direction, and if we’re sliding up, it alters d to it’s inflection… sliding the opposite direction (three quarters the way through the time would either be three quarters the way down if sliding down, or a quarter of the way from the top, if sliding up). Next we set the DIV’s height to “d” using it’s CSS style.height property.

Now, the last function we’re needing in the motionpack.js file is the endSlide() function:
function endSlide(objname){
  clearInterval(timerID[objname]);
 
  if(dir[objname] == "up")
    obj[objname].style.display = "none";
 
  obj[objname].style.height = endHeight[objname] + "px";
 
  delete(moving[objname]);
  delete(timerID[objname]);
  delete(startTime[objname]);
  delete(endHeight[objname]);
  delete(obj[objname]);
  delete(dir[objname]);
 
  return;
}
This is the function that’s called when the time runs out on an animation. It finishes everything and cleans up. The first line kills the animation timer, so it doesn’t keep trying to slide. The if-statement checks, and if it was sliding up, it hides the DIV by changing it’s display attribute to “none”. It readjusts the DIV’s height to the original height, so future animations will work fine on it. Then finally there are all those delete lines, deleting any array element we created to keep track of the different animations throughout the process. This cleans up a bit to ensure there are no memory leaks (for sites with lots of animations), etc. After this function is completed, the animation process is done.

Now you can save that file, with all the pieces above saved up, and upload it to your webserver.

To download the entire above JS file, you can get it here.

Now, we have our entire mini-library done…. so how do we use it?

First we need to include it in our website. This is done by adding this quick line to your website on every page that you’re using the animation, preferably in the HEAD tag:
<script language="JavaScript" src="motionpack.js"></script> This code assumes the file you uploaded is named “motionpack.js” and is in the same folder as your website source code itself. Another common practice is to create a folder called js/ and put all your javascript include files there together, and in that case, you’d change the src tag above line to “js/motionpack.js”. Easy.

Now that page of your website has sliding abilities! But how do we use them?

First, let’s create a DIV, like we did with our last collapsible DIV tutorial:
<div id="mydiv" style="display:none; overflow:hidden; height:95px;"><h3>This is a test!<br>Can you see me?</h3></div> Notice we did make one change though. We added an “overflow: hidden” attribute and “height:95px” to the style property of the DIV. These property MUST be present on all DIVs you use for sliding. If you don’t include the overflow attribute, it’ll look very ugly, with text overlapping on other content and such. If you don’t include a static height here, it won’t know how far to slide, so it won’t work at all. Aside from that, it’s virtually the same. You can put whatever you want inside the div, just be sure to adjust the height accordingly.

The difference is this time our link calls functions from our library above. Here’s an example of what a Slide Down link might look like:
<a href="javascript:;" onmousedown="slidedown('mydiv');">Slide Down</a> Notice in the onmousedown function we call the slidedown() function from our above library. This will begin the animation and slide the DIV down, until it’s completely visible. You can replace slidedown() with slideup() to do just that, slide the DIV up.

As a challenge to you, try using what you’ve learned in this tutorial and the last to create a toggleSlide() function. It would be a simple if-statement to check if the link’s “display” property, and either slide it up or down, depending on it’s state. We did something very similar in the last tutorial, so try applying that here!

And finally, he’s a working example of it:

Slide Down   |   Slide Back Up

Hope this helps!

Edit: Due to a high number of requests, I’ve made a followup post explaining how to use this code in a one-click toggle situation: Toggle Sliding DIV :)

  • 06
  • Mar

Ratings for the new James Bond: Casino Royale are through the roof. Every review site on the internet is hailing it as the best Bond movie yet. I love James Bond, but I HATED Casino Royale.

Casino Royale

This post has a bit of spoilers (not too bad though), so if you haven’t seen it yet… don’t. And if you have seen it, don’t see it again.

They killed every aspect of James that made him, well, Bond. When I think James Bond, I think girls, cars, gadgets, and a charming smoothness that make guys watching want to be exactly like him. Let’s analyze these in order. First girls… I’m not going to talk about this one in too much detail for fear of my girlfriend slapping me, but they casted ONE girl in the whole movie that attempted to tackle this bullet point. The second aspect of James Bond is cars. Granted he drove an Aston Martin DB9 Sport, which is a gorgeous car, and in one scene he jumps into the car in hot pursuit of the bad guy, and you expect a wild, explosive, Bond-like car chase. However to my dismay, that scene only lasts 20 seconds and the car is absolutely destroyed. Kinda sad for a car enthusiast. Next in line is gadgets. In Casino Royale there quite simply are no gadgets. There’s a cell phone with GPS and a GPS tracking bug… that’s about it. Impressive. Finally is Bond’s famous charm. In Casino Royale, he simply doesn’t have any. He’s egotistical and arrogant. He couldn’t care less about other people, and is completely sappy near the end. At one part my friend turned to me and asked “Is this James Bond, or a chick-flick?”

And another thing, Daniel Craig does not look the part of a smooth super-spy. Throughout the entire movie, that kept nagging at me in the back of my mind… he doesn’t look the part. Absolutely horrible casting.

This movie has tried to reinvent James Bond, but they’ve destroyed him. If they had not slapped the “James Bond” brand on it, and instead made a completely different movie, with a new name… it wouldn’t have been half bad. However they instead tried to expand on an existing image, and they ruined what was a good series. It almost seems like they made a separate movie, realized it was slightly similar, so they went back and changed a few parts so they could call it James Bond.

One example of how they’ve destroyed James Bond, was a scene where they asked him if he wanted his martini shaken or stirred… to which he replied “Do I look like I give a damn?”. I’m sorry… but James Bond would NEVER say that. He’s always polite, charming, and smooth…. not rough and a jerk, like he came off in this movie. I could go on ranting, but I think I’ve said enough. If you’re a James Bond fan, and you enjoyed this movie, can you PLEASE enlighten me as to why? Because as of now, I think that was the absolute worst James Bond movie I’ve ever seen… and I’d even go as far as saying it’s one of my least favorite movies overall.

Quite sad, really.

  • 05
  • Mar

I picked up the DVD for Jarhead the other day, and throughly enjoyed it. There were a few parts that were a bit extreme, but overall it was a very intense, well made movie. It makes anyone who watches it NEVER want to be a Marine (as long as you’re sane), heh. Jake Gyllenhaal is a fairly unknown actor (to me at least) who does an absolutely phenomenal performance, especially when paired with Jamie Foxx. I’d be curious to hear from an actual Marine how accurate this movie is, but from my perspective, it looks very realistic (or at least the studio did a good job with it).

Jarhead

And on that note, some links.
- IMDB: Jarhead
- Official Jarhead Movie Site

  • 05
  • Mar

Note, I’ve since made an updated post to this, with Digg comment style sliding animation included. Digg LinkActual Link

One of the most handy (and cool) tricks a web developer could learn to use is collapsible DIVs. This allows you to make a page that will only show the user what they want to see. If they’re interested in some part of content, such as a “mail to friend” or an expanded definition, they could click a link or image and make the page dynamically grow in size to show that added bit of content.

This was inspired by some comments in a post on Aaron’s SEO Buzz Box, and while I think he might be looking for a slightly more advanced solution, it gave me the idea to type up this post.

There’s a few different bits of code we’ll use in this. First we’ll create a div we want to expand or contract. For example:
<div id="mydiv" style="display:none"><h3>This is a test!<br>Can you see me?</h3></div> Notice our tagging the div with a unique id. This allows our Javascript to be able to find it when we alter it’s visibility. We also added a style property, setting it’s display attribute to “none”, which makes that DIV hidden when the page loads originally.

Next we’ll create a link with some inline Javascript to hide or show our div. It’s quite a bit to take in at once, but don’t worry I’ll explain it in depth in a second. Here it is:
<a href="javascript:;" onmousedown="if(document.getElementById('mydiv').style.display == 'none'){ document.getElementById('mydiv').style.display = 'block'; }else{ document.getElementById('mydiv').style.display = 'none'; }">Toggle Div Visibility</a> Whew! It’s so complicated because it’s done with inline Javascript. I’ll show an alternate method that’s much cleaner a bit later. But first, let’s tackle this. It’s a simple anchor tag, but you’ll notice the href is “javascript:;”. The purpose of this is to basically do nothing. You don’t want to direct to any other page, and if you put everything in the onmousedown property in the href property, it would work the exact same, but the user would see a mess of javascript in his status bar when he moused over the link, so this keeps it cleaner. Another common do-nothing insert to use for the href property is a pound sign (#), and while that will work, it’ll also move the user’s scroll bar to the very top of your website, which can get quite annoying.

Note, the following explanation is very detailed and assumes virtually no knowledge of Javascript… so if this seems basic to you, feel free to skip it.

Now, we have the href property clean so there’s nothing ugly in the status bar on mouseover, but we still need to actually do the hiding or showing of the div. We call this through the onmousedown property of the anchor tag. We can find the DIV we created earlier by document.getElementById(‘mydiv’), so we decide to first check if it’s already visible or hidden by running a simple if-statement of if(document.getElementById(‘mydiv’).style.display == ‘none’){. If this returns true, meaning the display property is set to none (hidden), we continue past the first bracket and change it’s display property to “block”, which means visible. This will also create a line break before and after our div, so if you want it to appear in the middle of your text or other content, without line breaks, change “block” to “inline”. Following that setting statement, we have our else block, which it run if the first clause isn’t met (the display is NOT set to ‘none’). If it’s not set to none, we assume the div is visible, so we toggle it and hide the div, setting it’s display property to “none” (hidden) again.

An alternative which is a bit cleaner than that inline anchor tag (above) is creating a javascript function for toggling the DIV’s visibility. For this method, use the following anchor tag:
<a href="javascript:;" onmousedown="toggleDiv('mydiv');">Toggle Div Visibility</a>This anchor tag behaves like the above inline javascript, except instead of executing the change in the anchor tag itself (inline), it instead calls the toggleDiv function, passing the div name as a parameter.

This anchor tag above calls the following function. Simply insert this text (the function) somewhere in your document above the link in the body tag, or in the HEAD tag of the HTML itself:
<script language="javascript">
  function toggleDiv(divid){
    if(document.getElementById(divid).style.display == 'none'){
      document.getElementById(divid).style.display = 'block';
    }else{
      document.getElementById(divid).style.display = 'none';
    }
  }
</script>
This function does exactly what the above inline javascript does, only it’s a bit cleaner. When it’s called by the anchor tag, it checks the div with the name passed to see if it’s currently not visible (display set to “none”), and if so, it shows it by changing the display to “block”. If the original if statement fails (display is not set to “none”), then it assumes the DIV is visible and hides it again (sets the display property to “none”).

Finally, here’s an example of it in action:

Toggle Div Visibility

Also note, search engines WILL read and index the content in these DIVs, so don’t worry about using collapsible DIVs hurting your SEO.

I’m planning on making another tutorial later talking about how to do this with a bit of animation (sliding the div down and back up again). Hope this is helpful!

  • 05
  • Mar

7Search is a hugely popular 3rd tier search engine with buying PPC traffic for arbitrage. Now, 7search has a mass-keyword submission page, but the catch is, if you don’t want to enter your keywords one by one, they won’t let you bid under $0.03. I personally go for some very long tail keywords, and I could rank with only paying $0.01 for them.

7Search was kind enough to leave a small hole/flaw in their system however. They only check the minimum bid via javascript client-side. And as such, there’s two very easy ways around this, which will allow you to bid $0.01 for your mass-added keywords.

Both of these methods have been tested on Firefox, but since I’m running Ubuntu Linux, I can’t test them in IE. I’d appreciate any feedback in the comments from people who’ve tested this in other browsers…. however in theory, it should work on all of them.

Method One
You could essentially overload the Javascript function. While you’re on the mass keyword adding page, enter this in your location bar (as if it were a website URL), and press enter: javascript:function validateBid(a){ } This essentially runs a bit of Javascript on the current page that wipes out their validation function. From here, you can set the bid to $0.01 and it will submit successfully.

Method Two
The second method is a bit more sneaky. It’s just a matter of cheating the order browsers parse the page. First enter your entire keyword list first, leaving the bid as $0.03 so it doesn’t complain. After you’re done, click up and change your bid to $0.01, leaving the cursor in the textbox (it complains as soon as you click or tab away). With your cursor still in the bid box you just changed to $0.01, click directly on the Submit button below your keywords. It will complain that the bid amount is too low, but then it’ll change pages and submit them as $0.01 after all. Simple. :)

I’m sure they’ll fix this soon, so enjoy it while it lasts. Good luck!