RSS Forums RSS
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 1083 | Replies: 2
Reply
Join Date: Nov 2007
Location: Reseda, California
Posts: 21
Reputation: scottholmes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
scottholmes scottholmes is offline Offline
Newbie Poster

add event listeners for dynamic list of objects

  #1  
Dec 19th, 2007
I have this bit of php that works fine as is but I would like to separate out the javascript calls to an onLoad function.

<?php
include("casefile.class");
$cf = new casefile_Rec;
$seclogin=$sess->getSessVar("seclogin");
if ($cf->primary_case_list($seclogin["uname"]))  {
        echo "<ul>";
        while ($row = mysql_fetch_assoc($cf->res)) {

                if ($aLine=="evenListing") { $aLine="oddListing";
                } else { $aLine="evenListing"; }

                printf("<div class=\"%s\">\n", $aLine);

                printf("<li><a onClick=\"wcmsJS.showCaseSummary('%s');\"
                        onDblClick=\"caseWindow('view&cnmbr=%s');\">%s</a>&nbsp;%s&nbsp;%s&nbsp;%s&nbsp;%s</li></div>",
                        $row["casenmbr"], $row["casenmbr"], $row["casecode"], $row["cswcab"], $row["csstamp"], $row["csclaim"], $row["casetyp_code"]);
        }
        echo "</ul>";
} else { echo "You have no Open Cases in the System<br>"; }
?>

This displays an unordered list of records, with alternating colors. Each element of the list has two events, onClick and onDblClick. Because the list is dynamic I have not assigned and id to each discrete <div>. An id is necessary for all event listeners I've seen so my question is what is a good way to create an array of objects and utilize the array in an onLoad (and onUnload) function.
Scott Holmes
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2007
Location: Russia
Posts: 11
Reputation: adorosh is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 1
adorosh adorosh is offline Offline
Newbie Poster

Re: add event listeners for dynamic list of objects

  #2  
Dec 22nd, 2007
I guess you should use JSON. Perhaps, I misunderstand the question, what is the task?
Reply With Quote  
Join Date: Nov 2007
Location: Reseda, California
Posts: 21
Reputation: scottholmes is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
scottholmes scottholmes is offline Offline
Newbie Poster

Re: add event listeners for dynamic list of objects

  #3  
Dec 22nd, 2007
The task is to separate the display from the data. In this case I'm not entirely convinced it is necessary but I thought worth exploring. I am going to be doing this in a large number of places in one of my current projects. It is widely held adviseable to not encode event handlers in display code, instead set up listeners. In this case each element in an array of records has both on onClick function and an onDblClick function.

I could create an array of strings (JSON perhaps) and save it in a session variable while creating the <ul> or <ol> of records, then let php create JavaScript functions called in onLoad and onUnload. Or, I can leave well enough alone which in this case actually seems easier to maintain. Anyway, I'm just fishing for advise here.
Scott Holmes
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 1:54 am.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC