Blog Tags

Lab Eleven Blogs

A short description about your blog

How to Stop a Form From Submitting on Enter

Posted by: twmeier

Tagged in: Javascript , HTML

I came across a problem this week, with a form that submitted when a user hit the "enter" or "return" button even though the submit button had an onclick function that should have kept the form from submitting. The problem only manifested itself on Google's Chrome browser.

I found the following JavaScript code to keep this from happening:

// Disables enter button from submitting the form
    var nav = window.Event ? true : false;
    if (nav) {
       window.captureEvents(Event.KEYDOWN);
       window.onkeydown = NetscapeEventHandler_KeyDown;
    } else {
       document.onkeydown = MicrosoftEventHandler_KeyDown;
    }
    function NetscapeEventHandler_KeyDown(e) {
      if (e.which == 13 && e.target.type != 'textarea' && e.target.type != 'submit') { return false; }
      return true;
    }
    function MicrosoftEventHandler_KeyDown() {
      if (event.keyCode == 13 && event.srcElement.type != 'textarea' && event.srcElement.type != 'submit')
        return false;
      return true;
    }

 
This worked great and fixed my problem (and hopefully your too).


Changing Page Title and Meta Info in Joomla

Posted by: twmeier

Tagged in: Programming , Joomla , Components

Changing the Page Title and the Meta Tags (keywords and description) in a Joomla Component is simple (this does not apply to articles or the home page of your site).

The first step is to include the following line of code inside php tags:

global $mainframe;

Then simply use the following functions to change the Page Title, Meta Keywords and the Meta Description:

$mainframe->SetPageTitle("Some Page Title");
$mainframe->appendMetaTag( "description", "Some Description.");
$mainframe->appendMetaTag( "keywords", "keyword, keyword2");

Since this code is php, it should all be inside php tags like it is below:


global $mainframe;

$mainframe->SetPageTitle("Some Page Title");
$mainframe->appendMetaTag( "description", "Some Description.");
$mainframe->appendMetaTag( "keywords", "keyword, keyword2");

?>

That is all there is too it. You will notice that your Meta Description and Keywords will be appended to your global Meta Description and Keywords, which can be found in the "Global Configurations" in the backend of Joomla.


Opening a New Browser Window

Posted by: twmeier

Tagged in: Javascript , HTML

There are times when you may want to open a page in a new browser window. You may also want to be able to determine the size of the new window, whether or not to have scroll bars, tool bars,  status bars etc..  There is a ready-made JavaScript function that you can use to do this:

window.open('url', 'window name', 'attribute1', 'attribute2', .....)

  1. 'url'
    This is the url of the page you would like to appear in the new window.
  2. 'window name'
    You can name your window whatever you like, which can be used if you need to make a reference to the window later.
  3. 'attributes'
    Attributes determine how the new window will look, and are listed below.

Attributes



Parsing an XML string retrieved using AJAX

Posted by: twmeier

Tagged in: XML , Programming , PHP , Javascript , Ajax

While working on an AJAX function this week, I found the need to parse an XML string using JavaScript and PHP. The following JavaScript was used to retrieve an XML string from a PHP file:

function someJavascriptFunction() {
      xmlHttp=GetXmlHttpObject();    
      url = "/components/com_component/ajax/ajax.php?task=someTask";    
      url += "&cc_number="+document.getElementById('cc_number').value;
      xmlHttp.open("GET",url,true);    
      xmlHttp.onreadystatechange = function() {
      if (xmlHttp.readyState == 4)  {       
           xmlDoc=loadXMLString(xmlHttp.responseText);
           var response = xmlDoc.getElementsByTagName("response")[0].childNodes[0].nodeValue;
           document.getElementById("someID").innerHTML = response;
     }
     xmlHttp.send(null);
}

function GetXmlHttpObject()    {
      var xmlHttp=null;
      try {
           // Firefox, Opera 8.0+, Safari
           xmlHttp=new XMLHttpRequest();
      }
      catch (e) {
           //Internet Explorer
           try {
                xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
           }
           catch (e) {
                xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
           }
      }
      return xmlHttp;
}

As you can see from the code above, the XML field I was interested in was the "response" field. The XML string that was created and passed using xmlHttp.responseText from the PHP file looked similar to this:

<authorizationResponse>
      <message>Some Message</message>
      <response>Some Message</response>
....
</authorizationResponse>

Not only did I need to parse the XML from the  responseText in javascript, but I also need to parse it inside the PHP function that the JavaScript function called. The XML above was retrieved from a payment gateway in the PHP function using CURL and naned $xmlString.

The only field I needed in the PHP file was the "message" field, and to retrieve it, (or any other field), I did the following in the PHP file:

$xml = new SimpleXMLElement($xmlString);
$message = $xml->authorizationResponse->message;

Don't forget you still need to echo out the entire XML string in your PHP file order to be used by your JavaScript function:

echo $xmlString;


Turn on Caching to Speed Up Your Joomla Site

Posted by: twmeier

Tagged in: Joomla

There is a simple and effective way to help speed up your Joomla site. It is called "caching". When you use the caching feature, Joomla creates a static file (or cache), of your web pages. This means that your website can use this cached file instead of making redundant database calls each time someone goes to a page. This in turn saves time and speeds up your site.


Creating a Joomla Menu Item

Posted by: twmeier

Tagged in: Joomla

Creating a new menu item in Joomla is extremely easy. Joomla uses these menu items to create a menu of links as seen below.

menu


How to add pages in Joomla

Posted by: twmeier

Tagged in: Joomla

The first step in adding a page in Joomla is to understand how Joomla displays pages. To display page, Joomla uses what it calls articles. Articles can be assigned to an infinite number of pages.

To create new articles, you must first sign in to the backend of you website:
http://your_domain_name.com/administrator


Joomla's Global Check-in Feature

Posted by: twmeier

Tagged in: Joomla

When a user is editing a content item, module, menu item etc., Joomla "locks" this item to other users. This insures that changes can not be made by different users at the same time. Below is a picture of what another user would see in the backend if he were to try to also edit the setting of the "Who's Online" module.

locked


Joomla 1.5 Popups

Posted by: twmeier

Tagged in: Joomla

Joomla 1.5 has a great pop up class which will dim the webpage and popup a smaller page over top of it. In order to use this feature, you must include the following in your code, or you could also place it inside your template between the tags.

JHTML::_('behavior.modal');

Then put in a link with the information you want similar to the one below:

popupcode

If you want to popup a page from your own website without all the menus and modules, then all you need to do is change the index.php in the URL to index2.php or adding &tmp=component to the end of the URL (if you do not have a ? in your URL use ?tmp=component).

Using Joomla's Media Manager

Posted by: twmeier

Tagged in: Joomla

There are times when you may need to upload an images, pdf or any other type of file to your site. Luckily, Joomla has a built in tool for uploading your files. This tool is called the Media Manager.


<< Start < Prev 1 2 3 Next > End >>

Latest Blogs

Fix Bad Credit With These Helpful Tips
Feb 26th 2013 by: Administrator

Will iPhone Apps Run On iPad?
Jan 29th 2010 by: Trevor M.

How to create a marquee text for an iPhone app
Jan 21st 2010 by: Trevor M.

How to Submit Additional Images in Virtuemart
Aug 7th 2009 by: Trevor M.

Using an Image as a Submit Button in HTML
Jul 31st 2009 by: Trevor M.

Read all blogs