CodeCharge Studio
search Register Login  

Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 Have the 1st item in listbox auto-selected when the page loads.

Print topic Send  topic

Author Message
bigtoe

Posts: 115
Posted: 07/05/2004, 11:29 PM

I have a text listbox "color" that gets its items from the database.

This listbox may contain:
"Red and Blue"
"White and Orange"
"Blue, Green and Pink"

OR the listbox may contain:
"Green"
"Pink, Blue, Purple, and White"
"Yellow and Blue"

OR any other list of colors.

All I know is that it will contain a list of colors.

Regardless of the colors, I need to make sure that the first listbox
item is always selected when the page loads.

I have set the Default Value to 1 for the listbox but that does not
auto-select the first listbox item on page load.


Is there something else I need to do?

View profile  Send private message
peterr


Posts: 5971
Posted: 07/06/2004, 12:28 AM

In the Default Value you would need to specify the value of the key (bound column) that you want to be selected. Looks like 1 is not it.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
bigtoe

Posts: 115
Posted: 07/06/2004, 2:01 AM

So if the listbox contains:
"Green"
"Pink, Blue, Purple, and White"
"Yellow and Blue"

And I want the 1st item to be the Default Value then I need to specify "Green" ?

View profile  Send private message
klwillis


Posts: 428
Posted: 07/06/2004, 8:25 AM

Programatically, you can do something like this within
the 'BeforeShow' event for the listbox ...

$ListForm->color->SetValue(x);

Where 'x' is the key value (i.e. "Green").

Like Peter said, it's the value of the listbox item and not
what's displayed that you need to use to select the item.

If you're colors are indexed by name, then "Green" should work.

You can also do this non-programatically by specifying "Green"
as the default value.

_________________
Kevin Willis, VP/CIO
HealthCare Information Technology Specialist
http://www.nexushealthcare.com
"Fast - Convenient - Quality-Care"

Medical Software Consulting Services
Email : klwillis@nexushealthcare.com
Skype : klwillis2006
View profile  Send private message
bigtoe

Posts: 115
Posted: 07/06/2004, 8:44 AM

There are 3 things that I have no control over:

a: The "T_color" table in the database contains just one column
called "C_colors" and there are no other columns.

b: The "C_colors" column currently contains the data:
"Green"
"Pink, Blue, Purple, and White"
"Yellow and Blue"

c: This "C_colors" data changes dynamically. A minute later it might be:
"Red and Blue"
"White and Orange"
"Blue, Green and Pink"


So I cannot simply put "Green" as the default value because
it might not be there later on.

Regardless of the row that shows up, I need to auto select the FIRST row.
So in case b it would be "Green" and in case c would be "Red and Blue".

How do I do this?
Remember, there is only ONE column in this table.

View profile  Send private message
peterr


Posts: 5971
Posted: 07/06/2004, 11:08 AM

To expand on klwillis' post, you can still use the code:
$ListForm->color->SetValue(x);

However, replace the 'x' dynamically with the value that is currently the first value in the database. I haven't tested this to give you the exact code but I assume that the CCDLookup function could work great for this.
http://docs.codecharge.com/studio/html/ProgrammingTechn...gleDBValue.html
Except in that example you could replace "user_name" with "First(user_name)" to obtain the first value and maybe "users" with "users ORDER BY xyz" for proper sorting.
You can also use the standard SQL to lookup the first value as shown at http://docs.codecharge.com/studio/html/ProgrammingTechn...leDBValues.html
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
klwillis


Posts: 428
Posted: 07/06/2004, 11:35 AM

I see now. ;-)

You'll need to do this programatically within
the BeforeShow event for the listbox.

Something like this ...


$items = array();

$db = new clsDBYourDataBaseConnection();
$db->query("SELECT C_Colors FROM T_Color");

$Result = $db->next_record();
while ($Result)
{
$color = $db->f("C_Colors");
$items[] = array($color,$color);
$Result = $db->next_record();
}
$db->close();

$YourDataForm->color->Values = $items;
$YourDataForm->color->SetValue($items[0][0]);

unset($items);

_________________
Kevin Willis, VP/CIO
HealthCare Information Technology Specialist
http://www.nexushealthcare.com
"Fast - Convenient - Quality-Care"

Medical Software Consulting Services
Email : klwillis@nexushealthcare.com
Skype : klwillis2006
View profile  Send private message
bigtoe

Posts: 115
Posted: 07/06/2004, 5:14 PM

Got it. Thank you.
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.

MS Access to Web

Convert MS Access to Web.
Join thousands of Web developers who build Web applications with minimal coding.

CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


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