JDev

java, strutsSeptember 29, 2006 2:19 pm

    It’s very easy to read request parameters with Struts Tag Library, although it took me a while to find this information:

<bean:parameter id=’project’ name="projectNumber"/> 

This tag reads the request parameter named projectNumber and saves it in a bean whose id is project.

Use a scriptlet to show the value of the request parameter on the page:

Project Number : <%= project %> 

Use the bean:write tag to display the value of session or request  attributes on the page:

<bean:write name="attributeName"/> 

 

php, mysqlSeptember 18, 2006 11:56 am

One can use the php function mysql_escape_string() to construct mysql queries that contain special characters like quotes, backslashes, etc. This function handles sinqle quotes well but does not seem to handle double quotes appropriately.

I got better results with the addslashes() function that handles both single and double quotes very well. 

Code, phpSeptember 16, 2006 3:14 pm

It took me a while to fix this problem. Nothing I did seemed to help. I put the session_start() statement at the beginning of the file, removed the whitespace before the session_start(). I still got the same error: Warning: session_start(): Cannot send session cookie - headers already sent by

Then I had another look at my code. It turned out the the opening php tag started on the second line, and the first line was empty. Once  I had removed the blank line, the error disappeared!

Also, if you have include files there should not be any blank lines after the closing php tag. This will cause the headers already sent error as well.

I have to thank the replies posted at the experts-exchange website that prompted me to see this error. 

dom, javascriptSeptember 15, 2006 5:50 pm

var cell = document.createElement("td");
cell.appendChild(document.createTextNode("sometext"));

javascript 2:04 pm

JavaScript has a concat() method that allows you to add contents of one array to another.

Example:

var ar1 = ["aa", "bb", "cc"];
var ar2 = ["dd", "ee", "ff"];

var ar3 = ar1.concat(ar2);

The new array ar3 will hold the contents of both arrays. The original array contents won’t change. 

For more JavaScript tips visit http://www.ekcsoft.com/coding/js.php

Code, dom, javascript 12:39 pm

Let’s say your link element (HTMLLinkElement)  is enclosed in a div with an id attribute "div1":

<div id=’div1′><a href=’somepage.html’>Go to some page </a></div>

Now to get to the text value of the link, first get a reference to the div element:

var oDiv = document.getElementById(’div1′);

and then use the innerHTML property

 alert(oDiv.firstChild.innerHTML);

This would work only if there is no whitespace or other elements between the opening div tag and the link.
If we know that the link  we want to get to is the first or only link in that div element we can use the following code:

var oAnchor = oDiv.getElementsByTagName("a").item(0);
 alert (oAnchor.innerHTML);

If you want to strictly follow the DOM specification, use the data property of a CharacterData object:

alert (oAnchor.firstChild.data);

You can also use the nodeValue property of a Node object:

alert(oAnchor.firstChild.nodeValue); 

HTMLLinkElement object properties and methods are listed here

javascriptSeptember 13, 2006 3:02 pm

It may not always be obvious that in JavaScript you can pass functions as arguments to other functions.

Here is a simple example:

function test1(name){
    alert("test1 "+ name);
}

function test2(name){
    alert("test2 "  +name);
}

function test(name, func){
    func(name);
}

Test the functions:

test("Tom",  test1 );
test("Katie", test2 );

The resulting alerts will carry the following messages:

 test1 Tom
 test2 Katie

  A good article on functional programming techniques can be found at this site.

View top-rated JavaScript books from the amazon.com site