PostIT

while scratching my head…

Dynamic form elements and Internet Explorer 6 June 30, 2009

Filed under: Internet Explorer, Javascript, Web Development — Remo @ 7:12 am

A few brief entries from the ‘tiny yet annoying bugs that take far too much time to fix’ file…

I’m creating forms dynamically using JavaScript. This has led to a number of problems with IE6:

Dynamic checkboxes/radio buttons and the ‘checked’ attribute

When creating a field, I wanted to be able to apply a ‘default’ value — for example, a checkbox element might be ticked by default. This was all going smoothly until (guess what?) I tested it on IE6: the checked attribute was set, and returned ‘true’ when tested, but the box did not appear to be checked when it appeared in the form.

The answer, as I discovered thanks to this forum post, was to use the ‘defaultChecked’ attribute instead (I set both, just in case). It seems to work across browsers, which is nice. Oh, and this applies to radio buttons as well as checkboxes.

Creating radio buttons

While we’re on the subject of radio buttons, I also found that IE6 doesn’t like radio buttons created using document.createElement() (i.e. as a DOM object). It’ll render them OK, but they’re unclickable. The answer is to create them by injecting HTML into an element with [element].innerHTML:

var obj = document.createElement( ’span’ );
obj.innerHTML = ‘<input type=”radio” name=”somefield” value=1>1′;

…and so forth. Ugly.

Assigning values to multiple select elements

This was a really fiddly one, and seems to happen under only very particular circumstances. Anyway…

If you create a select element and set the ‘multiple’ attribute, IE6 can sometimes have trouble assigning values to it if you do it immediately after it’s created. Note the word ’sometimes’: I haven’t been able to create a simple enough test case to isolate the exact circumstances that are required. And it’s only a problem if you’re setting more than one value.

Anyway, the (horrible) fix is to delay setting the values using setTimeout(). The delay doesn’t matter (1 millisecond will do), but it does work.

I hope these notes help some other unfortunate soul out there avoid wasting the number of hours and brain cells that I just have!

source:

http://the-stickman.com/web-development/javascript/dynamic-form-elements-and-internet-explorer-6/

 

PHP Execute Time Counter June 23, 2009

Filed under: PHP — Remo @ 2:00 pm
Tags:

This code is based on the ASP script posted by Lio. It will determine the time taken for a php script to execute correct to 0.000000000000001 seconds.

<!-- put this at the top of the page -->
<?php
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
?>
<!-- put other code and html in here -->

<!– put this code at the bottom of the page –>
<?php
$mtime = microtime();
$mtime = explode(” “,$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime – $starttime);
echo “This page was created in ” . $totaltime . ” seconds”;
?>

 

Install Smarty in Windows June 23, 2009

Filed under: PHP — Remo @ 12:53 pm
Tags: , , ,
This document assumes that your webserver and php5 is running.

Download Smarty - http://smarty.php.net

Installation - Windows, IIS/Apache, PHP5
Extract files, rename Smarty.x.x.x to smarty (suggest OUTSIDE of your www root!)
Example: d:\smarty
Run phpinfo.php to find out your php.ini location
Edit php.ini's include_path and add the location of the libs folder.
example: include_path = ".;d:\smarty\libs"
Restart IIS/Apache
Setup these two folders INSIDE your www root:
(wwwroot)/smarty/templates  (this is where your templates will go)
(wwwroot)/smarty/configs

Setup these two folders OUTSIDE of your www root:
d:/smarty/templates_c
d:/smarty/cache

Setup security settings for the webserver to write to these four folders

In (wwwroot) create index.php and in (wwwroot)/smarty/templates/index.tpl with the following code:

index.php:
<?php
// load Smarty library
require('Smarty.class.php');

$smarty = new Smarty;

$smarty->template_dir = 'd:/inetpub/wwwroot/smarty/templates';
$smarty->config_dir = ' d:/inetpub/wwwroot/smarty/config';
$smarty->cache_dir = 'd:/smarty/smarty_cache';
$smarty->compile_dir = 'd:/smarty/smarty_templates_c';

$smarty->assign('name','fish boy!');

$smarty->display('index.tpl');
?>

index.tpl
<html>
<body>
Hello, {$name}!
</body>
</html>

Now open index.php in your web browser (requested from your webserver)

http://localhost/index.php

You can work this out to a referenced script/class:
smarty_connect.php:
<?php

// load Smarty library
require('Smarty.class.php');

class smarty_connect extends Smarty
{
   function smarty_connect()
   {
        // Class Constructor.
        // These automatically get set with each new instance.

		$this->Smarty();

		$this->template_dir = ' d:/inetpub/wwwroot/smarty/templates';
		$this->config_dir = ' d:/inetpub/wwwroot/smarty/config';
		$this->compile_dir = 'd:/smarty/templates_c';
		$this->cache_dir = 'd:/smarty/cache';

		$this->assign('app_name', 'Intranet');
   }
}
?>

index.php:
<?php
require('smarty_connect.php');

$smarty = new smarty_connect;

$smarty->assign('name','Ned');

$smarty->display('index.tpl');
?>

index.tpl:
<html>
<body>
 Hello, {$name}!
</body>
</html>

If you are getting an error that Smarty.class.php isn't found
chances are that your include_path isn't correct or
you didn't edit the one that the webserver is using,
check your phpinfo.php!

source:
http://news.php.net/php.smarty.dev/2703
 

Multiple Inserts in 1 Query June 1, 2009

Filed under: Database, sql — Remo @ 8:15 am
Tags: , , , ,

$sql = "INSERT INTO beautiful (name, age)
VALUES
('Helen', 24),
('Katrina', 21),
('Samia', 22),
('Hui Ling', 25),
('Yumie', 29)";

source:

http://www.desilva.biz/mysql/insert.html

 

No Active Mixer Device… May 30, 2009

Filed under: Windows — Remo @ 3:34 am
Tags: ,

Start > Run > services.msc

Start Windows Audio Service

 

Friend of Friend May 22, 2009

Filed under: Database, sql — Remo @ 8:44 am

———-
UID | FID
———-
1 | 2
1 | 3
1 | 4
2 | 4
4 | 5
Dst…

UID: User ID
FID: Friends ID

—————————————————————————–

join similar table

select u1.uid as people, u2.fid as friend
from tabel u1
inner join tabel u2
on u1.fid=u2.uid
where u1.uid=1;

——————————————————–

select u1.uid as people, u3.fid as friend
from tabel u1
inner join tabel u2
on u1.fid=u2.uid
inner join tabel u3
on u2.fid=u3.uid
where u1.uid=1;

—————————————————————————–
search whose uid=1 :

SELECT fid FROM t WHERE uid=1

search friend of friend whose uid=1 :

SELECT fid FROM t WHERE uid IN (SELECT fid FROM t WHERE uid=1)

or (maybe) :

SELECT DISTINCT t2.fid FROM t t1
INNER JOIN t t2 ON t2.uid=t1.fid
WHERE t1.uid=1

merge friend + friend of friend, use UNION.
—————————————————————————–

display it like friendster do :

select u1.uid as first, u1.fid as second, u2.fid as third
from tabel u1
inner join tabel u2
on u1.fid=u2.uid
where u1.uid=1;

—————————————————————————–

1 level: (result: You > XXX > Target)

$sql=”SELECT friend_2.uid as XXX
FROM friend_3, _users
INNER JOIN friend_2
ON friend_3.fid = friend_2.uid
WHERE
friend_3.uid=$uid and
friend_2.fid=$fid and
limit 1″;
“);

2 level: (result: You > XXX > YYY > Target)

$sql=”SELECT friend_2.uid as XXX, friend_1.uid as YYY
FROM friend_3, _users
INNER JOIN friend_2
ON friend_3.fid = friend_2.uid
INNER JOIN friend_1
ON friend_2.fid = friend_1.uid
WHERE
friend_3.uid=$uid and
friend_1.fid=$fid and
limit 1″;

note: all friend table friend_1, teman_2, friend_3 has 75.000 rows,

problem:

1.very slow especially for 2 level
2. added with order by rand() sometimes time-out
3. how to make it simpler?

—————————————————————————

 

Browse With E-mail May 20, 2009

Filed under: Internet — Remo @ 7:24 am
Tags:

Send Email to browse@webinmail.com

Put the site address you want to browse as the subject

 

Total Commander Replacement May 18, 2009

Filed under: Software, Windows — Remo @ 2:52 pm
Tags: , , , ,

Today I’ve tried Double Commander – a file manager software which have a bit similar interface with Total Commander. One thing which attract me is that Double Commander is Open Source. Double Commander project hosted on SourceForge.NET, visit their the Project Page and give it a try.

You can also try Servant Salamander – a commercial product, but they also keep the freeware one which can be downloaded here.

Far Manager has text mode interface – similar with Total Commander predecessor: Norton Commander. Far Manager version 2.0 will become Open Source.

Have a visit also to other places which have broader review than mine:

 

Remove Windows Service May 16, 2009

Filed under: Windows — Remo @ 2:18 am
Tags: ,
1. Using INSTSERV
INSTSRV <SERVICENAME> REMOVE

2. Using SC.EXE from ResKit CD
sc delete <service_name>

3. Manually via Registry
HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services

Resource Kit can be downloaded here
 

Enable/Disable Regedit May 14, 2009

Filed under: Windows, security — Remo @ 11:13 pm
Tags: , ,

Create a VBS file, copy/paste this text into that file

Option Explicit

‘Declare variables
Dim WSHShell, n, MyBox, p, t, mustboot, errnum, vers
Dim enab, disab, jobfunc, itemtype

Set WSHShell = WScript.CreateObject(”WScript.Shell”)
p = “HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\”
p = p & “DisableRegistryTools”
itemtype = “REG_DWORD”
mustboot = “Log off and back on, or restart your pc to” & vbCR & “effect the changes”
enab = “ENABLED”
disab = “DISABLED”
jobfunc = “Registry Editing Tools are now “

‘This section tries to read the registry key value. If not present an
‘error is generated.  Normal error return should be 0 if value is
‘present
t = “Confirmation”
Err.Clear
On Error Resume Next
n = WSHShell.RegRead (p)
On Error Goto 0
errnum = Err.Number

if errnum <> 0 then
‘Create the registry key value for DisableRegistryTools with value 0
WSHShell.RegWrite p, 0, itemtype
End If

‘If the key is present, or was created, it is toggled
‘Confirmations can be disabled by commenting out
‘the two MyBox lines below

If n = 0 Then
n = 1
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & disab & vbCR & mustboot, 4096, t)
ElseIf n = 1 then
n = 0
WSHShell.RegWrite p, n, itemtype
Mybox = MsgBox(jobfunc & enab & vbCR & mustboot, 4096, t)
End If

source:

http://dougknox.com/security/scripts_desc/regtools.htm