JavaScript
  Home arrow JavaScript arrow Page 4 - Building the Behavioral Layer for a Networ...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVASCRIPT

Building the Behavioral Layer for a Network Processor with AJAX
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 1
    2006-12-27

    Table of Contents:
  • Building the Behavioral Layer for a Network Processor with AJAX
  • Listing the previous client-side code of the networking application
  • Querying an Internet host in the background
  • Turning query buttons into functional controls
  • Listing the full client-side code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Building the Behavioral Layer for a Network Processor with AJAX - Turning query buttons into functional controls


    (Page 4 of 5 )

    In order to assign multiple “onclick” event handlers to each of the query buttons integrated with the graphical user interface of the application, I’ll define the brand new “initializeControlPanel()” function, which performs this task.

    Having explained the capacity required for this new function, have a look at its definition. It is as follows:

    // initialize control panel

    function initializeControlPanel(){

                var form=document.getElementsByTagName('form')[0];

                if(!form){return};

                // assign 'onclick' event handlers to control buttons

                if(!form.elements[1]){return};

                form.elements[1].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=host','displayCommandResults')};

                if(!form.elements[2]){return};

                form.elements[2].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=ip','displayCommandResults')};

                if(!form.elements[3]){return};

                form.elements[3].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=iplist','displayCommandResults')};

                if(!form.elements[4]){return};

                form.elements[4].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=ping','displayCommandResults')};

                if(!form.elements[5]){return};

                form.elements[5].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=ipconfig','displayCommandResults')};

                if(!form.elements[6]){return};

                form.elements[6].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=netstat','displayCommandResults')};

                if(!form.elements[7]){return};

                form.elements[7].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=mxrecords','displayCommandResults')};

                if(!form.elements[8]){return};

                form.elements[8].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=serviceports','displayCommandResults')};

                if(!form.elements[9]){return};

                form.elements[9].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=servicenames','displayCommandResults')};

                if(!form.elements[10]){return};

                form.elements[10].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=scanport','displayCommandResults')};

                if(!form.elements[11]){return};

                form.elements[11].onclick=function(){sendHttpRequest
    ('query_processor.php?data='+document.getElementsByTagName
    ('form')[0].elements
    [0].value+'&command=nsrecords','displayCommandResults')};

                if(!form.elements[12]){return};

                form.elements[12].onclick=function(){

                            var centpanel=document.getElementById
    ('centerpanel');

                            if(!centpanel){return};

                            centpanel.innerHTML='';

                }

               

    }

    Although the above function seems to be hard to grasp at first glance, the truth is that its logic is very easy to understand. As you can see, the function in question is responsible for assigning an “onclick” event handler to each of the query buttons included with the respective user interface. It also triggers an HTTP request to the “query_processor.php” file each time a button is clicked on.

    In addition, you should notice that every time this action is taken, the aforementioned command variable is passed to the web server, in this way indicating to it what type of query should be executed in consequence. Indeed, the previous “initializeControlPanel()” function is pretty straightforward.

    Okay, now that you know how the two JavaScript functions that you learned do their things, it’s time to leap forward and see how all the parts of this networking application fit together. This will finish the entire client-side layer of the program would be finished.

    So do you want to see how the complete client-side code that belongs to this application looks? Click on the link below and keep reading.

    More JavaScript Articles
    More By Alejandro Gervasio


       · Over this second article of the series, the complete set of JavaScript functions...
     

    JAVASCRIPT ARTICLES

    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...
    - Dynamically Generate a Selection List in a R...
    - Intergrate DWR into Your Java Web Application
    - Detect Browser Compatibility with the Reques...
    - Using the EXT JS Date Picker Widget






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT