Archive for January, 2007

Get current URL with PHP

Monday, January 29th, 2007

Because I was having a “duh” moment. :)

$_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"]

Javascript Get or Set Checked Radio Value

Wednesday, January 24th, 2007

From Javascript Get or Set Checked Radio Value

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
if(!radioObj)
return "";
var radioLength = radioObj.length;
if(radioLength == undefined)
if(radioObj.checked)
return radioObj.value;
else
return "";
for(var i = 0; i < radioLength; i++) {
if(radioObj[i].checked) {
return radioObj[i].value;
}
}
return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) {
if(!radioObj)
return;
var radioLength = radioObj.length;
if(radioLength == undefined) {
radioObj.checked = (radioObj.value == newValue.toString());
return;
}
for(var i = 0; i < radioLength; i++) {
radioObj[i].checked = false;
if(radioObj[i].value == newValue.toString()) {
radioObj[i].checked = true;
}
}
}

floated box with extra (unintented) margin

Monday, January 22nd, 2007

Boy, do I love that “Position is everything” site. Every problem I’ve been having these days with CSS, the fix can be found there.

Here’s today’s CSS dilema. Had a simple floated div. Gave it a margin - and for some reason, IE doubled it. The solution is just to add “display: inline;” to the floated div, and all is well.

Floated boxes extending outside of container box

Saturday, January 20th, 2007

Ran into this problem today: Had a container div with floated divs inside. However the container div was shrinking up above the bottom of the floated divs inside.

See example here.

Found this solution which basically suggested adding the following so that it wouldn’t do that:

.containerdiv:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}

As well as adding a height: 1% (to to the container div)

See fixed example here.

Email Friendly URLs

Thursday, January 11th, 2007

Ever email someone a really long link and have the thing wrap to two lines, and then your friend gets the email clicks on the link but it’s broken so they can’t go to it? I just found this website: Email URL that will give you a simple URL to send to people and it will redirect them to the long complicated URL.

So for example this URL: http://www.amazon.com/o/ASIN/B000B7TBNE/ref=s9_asin_image_0/002-1630007-1917641
can simply be this url:
http://emailurl.com/1GZ374

No idea how long they store the referrer though. (I’ll bet you could write a script that basically does the same thing for your personal use and stores it forever on your own database…)

Vertical Center Text in DIV

Tuesday, January 9th, 2007

Like I said, I’m still fighting my way through understanding CSS. Here’s a little tid-bit I finally understand today. Had a bit of text that I wanted to have centered in a nav bar. “vertical-align: middle;” didn’t seem to do anything. Found this article which said this:

the thing with vertical-align is that it’s vertical aligning text according to the default line-height of the inline-text boxes. You can manipulate that by setting the line-height to the same height as your block, but this will only be effective if the line of text (link) does not wrap onto more than one line.

NOW it makes sense…

So if you had:

<div id="nav"><a href="#" class="centerme">Home</a></div>

Then:

#nav {
height: 25px;
line-height: 25px;
}
.centerme {
vertical-align: middle;
}

should do the trick…

1px Background Image Shift

Monday, January 8th, 2007

I’m still fighting my way to understand CSS - so if there’s a better way to do this, feel free to let me know.

I wanted a black center column, that I would put content boxes with a white background over it. So I created my background with the centered black column, used CSS to center it and repeat the background vertically. Then I created my content box, centered that using “margin: 0 auto;”. As per usual, looks great in Firefox, but IE has the box shifted over to the left by 1px.

See example here.

Poked around online. First I found this article which was talking about a different kind of shifting. They wanted you to add “html { min-height: 100%; margin-bottom: 1px; }” to your styles so that the page doesn’t shift suddenly when scrollbars appear on one page and not the other. (what they have you add forces scrollbars to show on every page)

Then I found this article which explains what’s happening. Because I’m centering the background via one method, and the content via another - this is the reason why it’s different. They suggest using a wrapper div to center the background - thus centering everything via the same method. The only problem with this is that I wanted that black column to extend the full height of the browser window. (below the content). Just doing “height: 100%” didn’t seem to work.

So I happened to have still put the code in for the scrollbar thing, and just for kicks added a 1px margin to the left side… and strangely it works. (At least on IE and Firefox on the PC. I don’t have access to a mac anymore, so no idea what happens there).

See revised example here.

I’m happy I got it to work.. but I’m not sure why it does.

Captcha

Thursday, January 4th, 2007

Just installed this captcha code on a form and it was extremely simple to do and so far seems to work great. Just thought I’d share. :)