CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Dynamically create javascript dropdown jump menu

Print topic Send  topic

Author Message
Aaron


Posts: 145
Posted: 11/27/2007, 3:38 PM

Here is the situation:
I have a grid showing people associated with an organization at an address with their contact information. For example: Joe Blow is at DataInc located at 123 Main Street. Work phone number 555-555-5555 and cell number 123-456-7890. This is on one row.

Next row has Jamie Joe at DataInc also at 123 Main Street, Work phone is 555-444-3333. And so on and so on.

Either on the front of each row, or at the end, I want to make a drop-down menu of the actions available. Ex: Edit person, edit contact info, delete person.

To do this now I can make a link that points to each of these pages with the appropriate place holders for PersonID, PhoneNumberID, etc that will be filled by the data in the row. But having 5 or 6 actions listed as individual links fills a lot of screen space. I want it in a drop down so the user can select "Edit person" and for the row they are on, it will see that the option for 'edit person' is to go to the page ../editPerson.php?PersonID=123.

Same thing for other options. Depending on the row chosen it needs to grab the associated ID numbers to dynamically populate the drop down in the correct place in the url. Any suggestions for this?

Thanks

Aaron
View profile  Send private message
datadoit
Posted: 11/27/2007, 7:04 PM

Sounds like a neat idea. May want to start by reading this post by
Nicole that explains how to get the values from editable grid rows:

http://forums.codecharge.com/posts.php?post_id=60507

You could dynamically build the values of the listbox by row, then use
javascript onchange event to redirect to your new page.

Just tossing ideas around...
Aaron


Posts: 145
Posted: 11/28/2007, 5:53 AM

Yes. I like that idea. I'll go & check out what she has. When I figure it all out, I'll post back, but I'm still open to ideas & some programmatic examples. :)

I was actually thinking of starting small; make the list fixed with only a handful of actions you can take for all instances then make it a bit more entertaining by adding, dynamically, actions that can only take place on a certain row because of... say, the person is of type "Physician" so you can modify physician-only related information about only them. Same for sales reps, etc.

Thanks again
View profile  Send private message
Aaron


Posts: 145
Posted: 11/28/2007, 7:13 AM

One thing I notice on her examples, they are all on Editable forms. I'm not doing any of this on editable forms, I'm doing this all on display grids. So I don't think using form names will work.
View profile  Send private message
datadoit
Posted: 11/28/2007, 8:31 AM

Aaron wrote:
> One thing I notice on her examples, they are all on Editable forms. I'm not
> doing any of this on editable forms, I'm doing this all on display grids. So I
> don't think using form names will work.
> ---------------------------------------

Seems that if you want to do this, the easiest method would be with
editable grids so that you can use CCS's CachedColumns array. See this
screenshot of how we do what you're talking about:

http://www.scholarshipfunding.org/images/action.jpg

The name of your checkbox is chkAction. The listbox will have values like:

field1-'new value';Do This;field2-'new value';Do That

Your button is simply a submit button. No operation. The Submit
button's Server OnClick custom code looks something like:

----------------------------------------------
global $DBConnectionDB;

$action = CCGetFromPost("Action","");

if ($action != "") {
# This fld value is from the list of values for action options.
$fld = split("-", $action); # [0] = column, [1] = desired value
$pk = $Container->CachedColumns['log_id'][0];
foreach ($Container->FormParameters['chkAction'] as $key=>$value) {
if ($value != "") {
$userid = $Container->CachedColumns['log_id'][$key];
if (strtolower($fld[0])=="deleted") {
$DBConnectionDB->query("SELECT log_id from log_users WHERE
log_id=" . $logid);
while (@$DBConnectionDB->next_record()) {
$DBConnectionDB->query("DELETE FROM log_users WHERE log_id="
.. $logid);
} //end of while loop
} //end of if 'deleted'
} //end of if a value
} //end of if record checkbox chosen
} //end of if an action was chosen
----------------------------------------------

You don't necessarily have to perform database actions on each option.
For example, many grids like this we have an action that will send an
email, or print detail forms for the records chosen, etc.

Thanks to DonB, the original creator of this idea/routine.
Aaron


Posts: 145
Posted: 11/28/2007, 11:08 AM

That's pretty much what I want to accomplish. I've been trying to get a simple one working, but am having problems.

I basically want the dropdown to say:

|---------------------------|
| --- Choose action ---- |
|---------------------------|
| ----- Update User ----- |
| - Update contact nfo - |
etc ...

So when the user has checked the box for that row & chosen, say, Update User, it will go to a predefined URL with placeholders for PersonID, AddressID, etc. So the url, after hitting submit would look like
.../updateUser.php?PersonID=1234&AddressID=4566
View profile  Send private message
datadoit
Posted: 11/28/2007, 7:00 PM

Aaron wrote:
> That's pretty much what I want to accomplish. I've been trying to get a simple
> one working, but am having problems.
>
> I basically want the dropdown to say:
>
> |---------------------------|
> | --- Choose action ---- |
> |---------------------------|
> | ----- Update User ----- |
> | - Update contact nfo - |
> etc ...
>
> So when the user has checked the box for that row & chosen, say, Update User,
> it will go to a predefined URL with placeholders for PersonID, AddressID, etc.
> So the url, after hitting submit would look like
> ../updateUser.php?PersonID=1234&AddressID=4566
>
> ---------------------------------------

Well, let's go back to having your listbox per row instead of a single
listbox with checkboxes on the records. Put a listbox on your row, and
dynamically set it's values in it's Server->Before Show event. Ex:

$Component->Values = array(array($Container->log_id->GetValue()."-Edit",
"Edit"), array($Container->log_id->GetValue()."-Print", "Print"));

'log_id' is any field value you want to use that's on your row. In my
case, 'log_id' is a hidden field on my row that contains the primary key
field value.

Then, in your listbox OnChange event, put:

popup(this)

Finally, in your HTML, add a javascript function like this:

function popup(list) {
var splitarray = list.options[list.selectedIndex].value.split("-");
testwindow = window.open
("test.php?id="+splitarray[0]+"&action="+splitarray[1], "mywindow",
"location=1,status=1,scrollbars=1,width=300,height=300");
testwindow.moveTo(0,0);
}

Similar concept as in the example I sent earlier, we're putting a couple
of needed values into our listbox value, then splitting it out into an
array later for dissemination.

With those values, then you can do what you want to do. In this
example, I'm just showing a popup window with the QueryString
parameters. You can, of course, test for the values of the split array
and react accordingly (open different windows, parent location to a
different page, etc.). Ex:

if(splitarray[1]=="Edit"){
do this;
}
if(splitarray[1]=="Print"){
do that;
}

Aaron


Posts: 145
Posted: 11/29/2007, 6:21 AM

Thanks datadoit! That was pretty much what I was looking to do.

I managed to make this concept work fine by hand coding it all yesterday, but I always seem to have issues trying to make things work the way I want in CCS. Mainly a matter of working with the templates, include files & such. Granted, CCS makes things easier in a way, but at times it can get frustrating.

Thanks again for the help!
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.