domingo, janeiro 22, 2006

Some fun with javascript, Shake it baby!

Just open a firefox or internet explorer window, rezise it and make it small, something smaller than 1/4 of your screen, then type one of this codes on the adress bar:



Shake it baby!


Dance dance!


Source: Forum Hardmob

sexta-feira, janeiro 20, 2006

Living and learning...

I think you all remember this post:php 2006 calendar

if you look at the comments, Zed said...

'cal 2006' has almost the exact same output and just needs to be wrapped in a pre-tag.

so.. all that stupid code i wrote can be changed to this:


$year = 2006;
exec("cal $year", $result);
echo "<pre>";
foreach ($result as $r) { print "$r<br />"; }
echo "</pre>";


i feel ashamed of my newbieness, but at same time, glad i shared this code and learned from my mistake :)

And i m sure you all remember this post as well:
Working with dates in php

Well, i make all that crap to compare 2 dates, but this strtotime() do the trick very easily, like this:

if(strtotime($date1) > strtotime($date2)) do_something();


How dumb can i be?

After all this, now i know that i can be pretty dumb :(

Form submission confirmation

Have you ever need to ask a user if he *really* wants to submit i form?
If you never had to do it, someday you will, so i ll share you some little code :)


function confirmSubmit(){
var agree=confirm("Are you sure you want to submit this?");
if (agree)
Submit();
else
return false ;
}

function Submit(){
document.forms['form_id'].method="post";
document.forms['form_id'].submit();
}


Use it like this:


<input type="submit" name="sub" value="Whatever" onclick="return confirmSubmit()" />


Do i need to explain?

Playing with javascript and checkboxes

As you may know already, when I want to do something, I try, try, till either one of these things happens: I make it work, or I die. I m still alive, so that means I won another one :)

The problem:
I was coding some user rights in a php system, it had some categories, and each category had a lot of stuff in it, and in almost all the cases the administrator want to set the rights by category and not one by one (imagine yourself clicking on 100+ checkboxes to configure the user rights), so i needed something that when you click on the category, it automatically checks all the sub-checkboxes in that category, that sounds easy, and it *was* until microsoft invented a virus called Internet Explorer.

The first version I made was easy and worked in the first try, but when I tried that on the stupid Internet Explorer, it didn't work, I tried changing a lot of things but it still didn't want to work, so I rewrote everything from scratch.


function checkUncheckAll(z,id) {
if(z == 100 || z == 200 || z == 300 || z == 400) {
var y = z+100, x = 0, x1 = 0, check = 0;
var inputs = document.getElementsByTagName("input");
x1 = 'ck_' + z + '_' + id;
x = 'ck_' + z + '_' + id;
for (var i=0; i<inputs.length; i++) {
if (inputs[i].name == x1) {
check = inputs[i].checked;
}
x = 'ck_' + z + '_' + id;
if(inputs[i].name == x) {
inputs[i].checked = check;
z++;
}
}
} else {
return false;
}
}

Use it like this:

<input type="checkbox" name="ck_400_1" onclick="checkUncheckAll(400, 1);" />


Let me explain, it is *very* important to name your checkbox like this: ck_400_1, ck_402_1, so when i click on the ck_400_1, it will sum 1 to 400 and loop till it checks all the checkboxes till 499, easy isn't it?

The secret to make it work on that virus called IE was this: var inputs = document.getElementsByTagName("input");

domingo, janeiro 01, 2006