Archive

Posts Tagged ‘Javascript’

Refresh the parent browser when the popup is closed

Saturday, November 24th, 2007

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.

Assign PHP array content to a JavaScript array

Tuesday, May 15th, 2007

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.

Trim function applied to Javascript

Saturday, February 24th, 2007

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

Recent Comments

  • Stanford Reach: Great post. Thanks!
  • Shu Crunk: I was simply browsing for useful blog articles intended for a project research and I happened to stumble...
  • Marya: Hey rather wonderful weblog!! I’ll bookmark your weblog and grab the feeds conjointly…
  • John Vay: ive just started my own hosting company its such hard work haha :P
  • write a good resume: Your the best!