Medion hints (PHP, MYSQL, HTML/CSS2, Javascript and use of DOM, AJA(X or J))

From Elvanör's Technical Wiki
Jump to navigation Jump to search

Name of class beginning with a number in XHTML/css2

You may read it's not allowed or just not handled by Opera and Firefox through the web, but it's false. The truth is it's allowed but must be done in a certain way (IE does it is own way, as always).

I will use here regexp notation, simpler way to explain the trick.

In the XHTML code you can call a class with class="([0-9])([:alnum])"

But in the css code, if you declare .($1)($2) it won't work. The thing is that you must escape the first digit. Actually, it will always work with that: class="([0-9])([:alnum])" on XTHML, and .\3($1) ($2) on css2 (don't forget the space after ($1)!!!

Don't worry, it will pass W3C validation without a problem, the parser will see ".($1)($2)"

Using the DOM on IE

setAttribute doesn't work with IE, so using librairie like prototype is better and produces crossbrowser results (will do a little paragraph on it later).

Still, there are some problems remaining and you need to handle.

-Drop down menu case: On every browser, you can add an option to the "select" with (selectElement).add(oOption, null);

But on IE, acording to the documentation, you should use (selectElement).add(oOption, 1).

Still, in a loop constructing the drop down menu like this:

for(i=0;i<array.length;i++){
   var oOption = document.createElement('OPTION');
   oOption.value = array_[i]["value"];
   oOption.text = array[i]["text"];
   (selectElement).add(oOption, 1);	
}

,it tends to invert the natural order of the options, so you must use (selectElement).add(oOption, -1) instead

If you want to assign the selected value, you can do

function Select_Value_Set(selectid, valeur){
      var SelectObject = (selectElement);
      for(index = 0;index < selectElement.length;index++){
         if(SelectObject[index].value == valeur)
             SelectObject.selectedIndex = index;
     }
}

And then call Select_Value_Set after the construction of the menu. Still, I experienced strange problems with IE, i must call twice the function to have it work...

Problems with PHP + DHTML on Opera browser (tested on Opera 9.10):

Some problems appear on Opera but i can't explain why... Your dynamic links (like <a onclick="document.getElementById(id).setAttribute('style','display:block;');">test</a>) will execute the javascript instruction then reload the page!

For instance if you want to create an hidden div that appears on click you will create an hidden div with a link inside:

<div id="hideAndAppear" style="display:none;">
<a onclik="document.getElementById('hideAndAppear').setAttribute('style','display:none;');">Hide me!</a>
</div>

And a link in the page:

<a onclick="document.getElementById('hideAndAppear').setAttribute('style','display:block;');">Show me!</a>

When the link reloads the page instead of just doing the javascript, you must change the name of the script, and it works again... What a pain!

Don't know why yet...

Requests to update posts of IPB forums

Sometimes when you change of IPB forum version, change the smileys or your specifics tags it would be great to update all posts to change the tags.

Here are the SQL requests to handle that:

One part tag:

UPDATE ibf_posts
SET post = CONCAT(
    SUBSTRING_INDEX(post,"string",1),
    "string_remplacement",
    SUBSTRING_INDEX(post,"string",-1)
    )
WHERE LOCATE("string",post)<>'0'

Two parts tag:

UPDATE ibf_posts
SET post = CONCAT(
    SUBSTRING_INDEX(post,"string1",1),
    "string1_remplacement"    ,
    SUBSTRING_INDEX(SUBSTRING_INDEX(post, "string1",-1),"string2",1),
    "string2_remplacement",
    SUBSTRING_INDEX(post,"string2",-1)
    )
WHERE LOCATE("string1",post)<>'0'

Making your Apache server interpret new extensions

Sometimes you may want to make your Apache interpret new extensions (for instance .php5 if not recognized). Very easy, juste go to your httpd.conf and add index.php5 on the DirectoryIndex line, then add AddType application/x-httpd-php .php5 below the others AddType. Restart, job's done!