JDev

Code, phpJuly 27, 2007 11:48 am

This message "Notice: Undefined index:" shows up in php pages when an element does not exist in an array, e.g.

if($arr[’$elementName’])… 

The cure is simple: put isset() around it. e.g.:

if(isset($arr[’$elementName’]))

 

Code, cssJuly 19, 2007 8:07 pm

If lines of text inside the pre tag are too long  it may mess up the page layout in IE.
Use the following style from  Tero Karvinen:
 white-space: pre-wrap;       /* css-3 */
 white-space: -moz-pre-wrap;  /* Mozilla, since 1999 */
 white-space: -pre-wrap;      /* Opera 4-6 */
 white-space: -o-pre-wrap;    /* Opera 7 */
 word-wrap: break-word;       /* Internet Explorer 5.5+ */

Code, javascript, ajaxJuly 17, 2007 6:42 pm

Let’s say you want to bring down a list of names from the server and display them without reloading the page.

I’ll show you a simple way to do it using the Ajax technology.

1. Create a form:

<form name="frm" action="#" autocomplete=off onSubmit="getIt();return false;">
   <fieldset>     
    <label for "id">Enter name:</label>
    <input size="20" type="text" id=’id’ name="name" value='’><BR>   
    <input type="submit" name="doit" value="submit">
    </fieldset>
</form>

The submit even will call a JavaScript function getIt(). We’ll get to it later.

2. Create a div

<div id=result> </div> 

3. Get a reference to XMLHttpRequest object.

    function getHTTPObject() {
        if (typeof XMLHttpRequest != ‘undefined’)
        { return new XMLHttpRequest(); }
        try { return new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (e)
        { try { return new ActiveXObject("Microsoft.XMLHTTP"); }
        catch (e) {} }
    return false; }

    var xmlhttp = getHTTPObject();
        

 4. Create a getIt()  function:

function getIt( ) {              
        if( xmlhttp) {
            var url =’servlet/myClass’;
            var target = document.getElementById("id");            
            url += "?id=" + encodeURIComponent(target.value);
            xmlhttp.open(’GET’, url, true);
            xmlhttp.send(null);
           
            var divResult =document.getElementById(’result’);              
            xmlhttp.onreadystatechange = function (){

                if (xmlhttp.readyState == 4) {
                       if (xmlhttp.status == 200) {                           
                            divResult.innerHTML = xmlhttp.responseText;
                   }   
                } 

           }

        }                
    }    

Code, javascript, ajaxJuly 11, 2007 7:53 pm

Here’s a simple way to generate an hourglass on demand, regardless of what the mouse is over.
Create a document-element class:

html.waitCursor * { cursor: wait; }

When the <html> tag has a class of "waitCursor", the mouse would become an hourglass over the entire page and all elements, including any margin outside the BODY area. Create a pair of simple functions that can be called in global scope:

function beginWait { document.documentElement.className = ‘waitCursor’; }
function endWait { document.documentElement.className = ‘’; }

From John Black on http://swik.net/Ajax/Ajax+Mistakes 

CodeJuly 10, 2007 5:16 pm

If you want to use DOM to create a table row with a cell that has a colSpan attribute you are in for a surprise. Internet Explorer will produce an error if you try to set a colSpan attribute on a cell element.

Here is the solution

       var tr = document.createElement(’tr’);
           
       if(!document.all) {

            // non-IE browsers
            var td = tr.insertCell(0);
            td.colSpan = 4;   
            td.align = "center";       
        }
        else {           

            //IE code
            var td = document.createElement(’<td colspan="4" align="center"></td>’);                       
        }   
       
        td.innerHTML = "HELLO";
        tr.appendChild(td);