Developer Blog

You are currently browsing the archives for the Web Scripting category.


Archive for the 'Web Scripting' Category

Assign PHP array content to a JavaScript array

Wednesday, December 6th, 2006

Sometimes we need to transfer the server side data to client side. Means we may need to transfer PHP variable or array values to Javascript variable or values. The following script will solve this problem very well.

$aDatas = array();
$aTitles = array();
$iMaxCount = 10;
for($iCount=0; $iCount< $iMaxCount; $iCount++)
{
 $aDatas[$iCount] = $iCount +10;
 $aTitles[$iCount] = 'Title'. $iCount;
}

?>

Make sure that you have given single quote before and after PHP tag, while assigning STRING values from PHP variables to JS.

Why a web page needs to be XHTML & CSS validated?

Saturday, November 11th, 2006

While developing a web page, we normally go for XHTML (preferably, Strict 1.0)  & CSS2 validation. This is due to the following reasons:

  • All browsers are competing to comply to the W3 standards. Suppose, for example, an updated version of a browser is released. Our web page may not look as expected if the page does not comply to w3 standards. If we have validated it then it will look fine in the new versions of browsers without making any further changes to the source code.
  • There are lot of browsers in web world. While developing a web page we don’t get chance or time to test our pages in all browsers. But if we have made our page XHTML & CSS validated then we can well be assured that the web page will retain most of its original look & feel in all browsers.
  • Search bots find complied (or validated) pages easy to index.

We can check our web page against XHTML validation at:

  1. XHTML: http://validator.w3.org/
  2. CSS: http://jigsaw.w3.org/css-validator/

 

Underline on mouse rollover

Wednesday, November 8th, 2006

Underline on mouse rollover

There are two ways of achieving this functionality

1. Javascript
2. CSS

Javascript:
By using “onmouseover” and “onmouseout” events which calls two user defined functions “blockStyle(’param’)” and “displayStyle(’param’)”,where param is a unique id for that hyperlink when the event occurs.
Eg. <a onmouseout=”blockStyle(’link’)” onmouseover=”displayStyle(’link’)” href=” ” mce_href=” ” >click here</a>

CSS:
By using hover.
Write this source code in the css file.
 a:hover
 {
      text-decoration:underline;
  color: blue;
 }
This above code will affect all the hyperlinks(anchor tag) in the same webpage.

Trim function applied to Javascript

Monday, November 6th, 2006

The following code will help to apply “Trim” function in javascript. Here is an example where we are retriving data from a prompt message box then applying “Ltrim” & “RTrim” like functions. 

var sData = prompt(”Enter The Name”,”");           // Receives data from user
 var sLeft = /\s*((\S+\s*)*)/;
 var sRight = /((\s*\S+)*)\s*/;
 sData = sData.replace(sLeft, “$1″);              // Removes blank spaces from left
 sData = sData.replace(sRight, “$1″);           //  Removes blank spaces from right

Time calculation of various Timezones

Monday, November 6th, 2006

function calcTime(sCity, offset)
{

    // create Date object for current location
    d = new Date();
   
    // convert to msec
    // add local time zone offset
    // get UTC time in msec
    utc = d.getTime() + (d.getTimezoneOffset() * 60000);
   
    // create new Date object for different city
    // using supplied offset
    nd = new Date(utc + (3600000*offset));
   
    // return time as a string
    sDateTime = nd.toLocaleString();   // It is total datetime format
    
    document.write(sCity+” : “+sDateTime);    
   
}

// Set the time for countries
calcTime(’London’, ‘+0.0′);              // ‘+0.00′ is the standard timezone of London
calcTime(’Sydney’, ‘+10.0′);
calcTime(’New York’, ‘-5.0′);

Refresh the parent browser when the popup is closed

Monday, November 6th, 2006

When you click on a hyperlink on the popup window the popup closed & the parent window needs to be refreshed.

 To satisfy this need you have to write the following code in the hyperlink (”close window”) of popup window.

javascript:self.close();         // closes the current window (Popup).

opener.location.reload();     // Reloads the content of the parent window.

Get Download Files Review Project Dashboard Know Plan And Wishlist