Adding leading zero’s and id’s with php

October 28th, 2008 § 0

For a project of mine I had to make a dynamic filename
We decided that the name should always be seven digits long and the file would be correspondentĀ  to the line number in the database. For example line seven would link to a file 0000007.txt.

code for the id from MySQL
$mynr = mysql_insert_id();

code for the seven digits
$mynr = sprintf(”%07d”,$mynr);

Related Blogs

  • Related Blogs on

Javascript date object

October 27th, 2008 § 0

var mytime = new Date()
var mymonth = mytime.getMonth() + 1 // for javascript january = 0  correct this by adding 1
var myday = mytime.getDate()
var myyear = mytime.getFullYear()
document.write(mymonth + "/" + myday + "/" + myyear)
Beware that this is the date on the client's computer. For forms use the date on your server.

Related Blogs

  • Related Blogs on

Checking radiobuttons with Prototype

October 23rd, 2008 § 0

example:
<input type='radio' name='test' value='1' />
<input type='radio' name='test' id='nr2' value='2' />
<input type='radio' name='test' value='3' />

$$("input[type=radio][name='test'][value='3']")[0].writeAttribute("checked", "checked");
or
$("nr2").writeAttribute("checked", "checked");

Related Blogs

Browsersniffing with CSS

October 21st, 2008 § 0

After some research I found the follow css code for sniffing out browsers and emailclients through css. /*Internet Explorer*/
<!--[if IE 7]>
.glue{color: black;}
<![endif]-->

<!–[if IE 6]>
.glue{color: blue;}
<![endif]–>

/* outlook 2007*/

<!--[if gte mso 9]>
.glue{color: aqua;}
<![endif]-->

/* Firefox */
@-moz-document url-prefix() {

.glue { color: red; }
}

/* Opera */
@media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) { .glue { color: yellow; }
}

Prototype stripTags

October 13th, 2008 § 0

Prototype’s stripTags function needs a string as input. If you want to access a dom node with this function, you need to acces the innerHTML, else the input won’t match.

expl.

alert($(’mydiv’).stripTags(); -> wont work
use

alert($(’mydiv’).innerHTML.stripTags();

Related Blogs

  • Related Blogs on Prototypejs
  • Related Blogs on striptags()

Copy to clipboard with Prototype

October 9th, 2008 § 0

Joe Gornick wrote a Prototype extension that lets users copy data to the clipboard.
The code uses javascript in Internet Explorer and some flash for other browsers.
Check it out at Joe Gornick’s site.

Prototype css selectors and observe

October 9th, 2008 § 0

When using $$ in Prototype, the result is an array. You need to loop through the array to attach the observe function. Expl.
$$(’.myitems‘).each(function(item) { item.observe(’click’,function(){alert (’clicked’)});});

or

$$(’.myitems’).invoke(’observe’, ‘click’, function() {alert(’clicked’)});

smaller images

October 9th, 2008 § 0

Some things to keep in mind when using images:

  • jpeg’s are for pictures
  • gif was for logos, use png-8 instead (sidenote)
  • use smushit.com to remove metadata
  • when possible use tiles

javascript variables

October 9th, 2008 § 0

Make sure your variables in javascript are unique. They should not be used in id’s and classes. IE doesn’t like it. (Works fine in Firefox)

Fire events with Prototype

October 9th, 2008 § 0

It’s not possible to fire the default events with Prototype 1.6. Only custom events are supported.

$(’mybutton’).observe(’click’,function(){…});
$(’mybutton’).fire(’click’); will not work

$(’myinput’).observe(’input:changed’,function(){….});
$(’myinput’).fire(’input:changed’); does work

Where Am I?

You are currently browsing the a note to self category at westworld: a webmasters best friend.