ajax XML


header('Content-type: text/xml');

<?php echo $description; ?>


httpRequest.responseXML.getElementsByTagName('description')[0].firstChild.data;

javascript trim function

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
return stringToTrim.replace(/\s+$/,"");
}

javascript drag and drop



drag Me!



CSS selector

input[type=submit]:hover, input[type=button]:hover{
  background-color:#FFBBCC !important;
}

Mysql update with conditional

+----+----------+--------+
| id | code |subcode |
+----+----------+--------+
| 1 |A001-123 | A001 |
| 2 |A001-123 | D003 |
| 3 |A001-456 | A001 |
| 4 |A001-456 | A001 |
| 5 |A001-456 | D002 |
| 6 |A001-789 | A001 |
+----+----------+--------+

UPDATE test as t1,
(SELECT code,
replace( substring( substring_index( code, '-', 2 ),
length( substring_index( code, '-', 2 -1 ) ) +1 ) ,
'-', '' ) AS ref //split
FROM test
WHERE code IN(
'A001-123', 'A001-456', 'A001-789'
) GROUP BY code
) as t2
SET t1.subcode=
IF(t1.subcode='A001', 'A002', t1.subcode) ,
t1.code=concat("A002-",t2.ref)
WHERE t1.code IN(
'A001-123', 'A001-456', 'A001-789'
) AND t1.code=t2.code


+----+----------+--------+
| id | code |subcode |
+----+----------+--------+
| 1 |A002-123 | A002 |
| 2 |A002-123 | D003 |
| 3 |A002-456 | A002 |
| 4 |A002-456 | A002 |
| 5 |A002-456 | D002 |
| 6 |A002-789 | A002 |
+----+----------+--------+

MYSQL split delimited strings functions

It's pretty easy to create your own string functions for many examples listed here

## Split delimited strings

CREATE FUNCTION strSplit(
x varchar(255),
delim varchar(12),
pos int
)
returns varchar(255)
return replace(substring(
substring_index(x, delim, pos),
length(substring_index(x, delim, pos - 1)) + 1),
delim, '');


select strSplit("aaa,b,cc,d", ',', 2) as second;
+--------+
| second |
+--------+
| b |
+--------+

select strSplit("a|bb|ccc|dd", '|', 3) as third;
+-------+
| third |
+-------+
| ccc |
+-------+

select strSplit("aaa,b,cc,d", ',', 7) as 7th;
+------+
| 7th |
+------+
| NULL |
+------+
Credits go to Chris Stubben

getElementById('description').value + IE javascript bugs

Let say you have a html like below.

<html>
<head>
<title>IE document.getElementById bug</title>
<meta name="description" content="IE bugs" />
</head>
<body>
<textarea name="description" id="description">
This is information about the bug
</textarea>
<script type="text/javascript">
alert(document.getElementById('description').value);
</script>
</body>
</html>

okay,

If you view the example in Firefox, you will get a JavaScript alert message :
  This is information about the bug

However, if you view it in IE7 the JavaScript alert will contain the word “undefined”.

The error is caused because IE’s document.getElementById(’description’) sees the meta tag with the name attribute set to “description” and since it treats name and id attributes as interchangeable, returns the meta tag instead of the textarea which actually has an id set to “description”.

JavaScript programmers who are familiar with this bug often take great care to avoid the problem by being circumspect with the names and ids of their elements. However, this becomes increasingly difficult as applications become more complex with multiple reusable parts that are included into various parts of the same system, especially with multiple programmers working concurrently. Naming conventions can help, but there are times when the id of an input element (which must be unique) differs from its name attribute, which does not have to be unique.

How to solve it,
You can change the textarea name . May be change to "desc"

Other Solution or more details can take a look on this post:
http://www.sixteensmallstones.org/ie-javascript-bugs-overriding-internet-explorers-documentgetelementbyid-to-be-w3c-compliant-exposes-an-additional-bug-in-getattributes