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 Modify ListBox Values

Print topic Send  topic

Author Message
Damian Hupfeld
Posted: 02/09/2005, 2:46 PM

I have 3 tables

adv
-id
-email
-pass
-name
-stateid
-regionid

state
-stateid
-state

region
-regionid
-stateid
-region

I have a registration form.
User enters his data in form.
State is a ListBox pulling its data from State Table.
I need to make Region a ListBox pulling its data from Region Table but only
pulling regions where the value selected in the stateid field is equal to
stateid in the Region Table.

The following SQL query would pull the right set of data EXCEPT that there
isnt a value in the adv.stateid field until the form is submitted.

SELECT regionid, region.region AS region_region
FROM region INNER JOIN adv ON
region.stateid = adv.stateid

I need to somehow run the SQL query based on the FORM value.

Any Ideas?



peterr


Posts: 5971
Posted: 02/09/2005, 4:46 PM

SQL cannot be run within HTML page, only on the server after page is submitted.
Best solution may be to use 2 dependent listboxes as in CCS Example Pack 2:
http://examples.codecharge.com/CCSExamplePack2/Dependen...dentListBox.php
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Damian Hupfeld
Posted: 02/09/2005, 5:09 PM

Cant do it this way because it blanks my text fields on Submit and doesnt retain my STATE setting for the State field.
I will probably have to have the registration go over more than one page.
Damian Hupfeld
Posted: 02/09/2005, 5:15 PM

Can JavaScript run SQL queries?
peterr


Posts: 5971
Posted: 02/09/2005, 5:46 PM

JavaScript and generally Web browsers cannot run SQL queries. They can only display and manipulate the data sent from the server.
That problem with retaining values and states can probably be fixed though, if you post some details (although I may not be able to help with that as I haven't worked with that example).
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Damian Hupfeld
Posted: 02/09/2005, 5:56 PM

If you see the original post PeterR you will see that there are some text
fields (email, pass, name, and the actual page has several more) and 2 list
boxes (stateid and regionid). Using the example when the page refreshes and
passes the paramater

register.php?stateid={stateid}

the text fields all become blank and even the stateid field becomes blank.

If I make statedid= as a parameter for the stateid it will retain the value,
however if someone has accidentally clicked the wrong state in the first
instance they cannot go back and update it!

Does that explain it more clearly?

Damian
http://www.nexthost.com.au/services.php
peterr


Posts: 5971
Posted: 02/09/2005, 6:13 PM

That example was created specifically not to refresh the page. The page is NOT being refreshed when you select a category or product at http://examples.codecharge.com/CCSExamplePack2/Dependen...dentListBox.php and nothing becomes blank.
That's why I pointed you to that example...
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
peterr


Posts: 5971
Posted: 02/09/2005, 6:14 PM

(sorry, the page is being refreshed when you select product, but not when you select category, which is exactly what you need, I think)
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Damian Hupfelfd
Posted: 02/09/2005, 7:28 PM

Sorry PeterR - Support referred me to a different Dependant listbox exampple and I mistakenly thought that you were referring me to that one. I will check it out this afternoon.

Thanks
Damian
http://www.nexthost.com.au/services.php
Damian Hupfeld
Posted: 02/10/2005, 5:04 AM

Wow!

What a struggle for my poor tired brain. The example uses Search Grids and
an output Grid on the same page. I am trying to Input Data into the table...
and Im trying to work thru the examples...


Added the following to my <script> section
-----------------------------------------------------------------------------

//Dynamic List Box
var DomYes=document.getElementById?1:0;

function set_child_listbox(parentObject,childObject,childArray,spanToHide) {

//Clear child listbox
for(var i=childObject.length;i>0;i--) {
childObject.options = null;
}

childObject.options[0] = new Option("Select Value","");
var sel_index = parentObject.options[parentObject.selectedIndex].value;
if (sel_index == "") {
childObject.disabled = true;
} else {
childObject.disabled = false;
var childIndex = 1;
for (i = 0; i < childArray.length; i++) {
if (childArray[1] == sel_index) {
childObject.options[childIndex] = new Option(childArray[2],
childArray[0]);
childIndex++;
}
}
}
//Select first option
childObject.selectedIndex = 0;

//Hide dependent grid
if (spanToHide != "") {
if (DomYes) {
document.getElementById(spanToHide).style.display="none";
} else {
document.all[spanToHide].style.display="none";
}
}
}

function reload_page() {
var sel_index =
document.adv.state.options[document.adv.state.selectedIndex].value;
var sel_subindex =
document.adv.region.options[document.adv.region.selectedIndex].value;
if (sel_subindex != "") {
document.location.href = document.location.pathname + "?" + "regionid=" +
sel_subindex+"&stateid=" + sel_index;
}
}

function disable_child_listbox(spanToHide) {

//Disable second listbox
if (document.adv.state.selectedIndex == "") {
document.adv.range.disabled = true;
}

//Hide dependent grid
if (document.adv.range.selectedIndex == "") {
if (spanToHide != "") {
if (DomYes) {
document.getElementById(spanToHide).style.display="none";
} else {
document.all[spanToHide].style.display="none";
}
}
}
}

window.onload = function() {
disable_child_listbox("Range");
}


<!-- BEGIN Grid region -->
var Region = new Array(
<!-- BEGIN Row -->
new Array({regionid},{stateid},'{region}')<!-- END Row --><!-- BEGIN
Separator -->,<!-- END Separator --> );
<!-- END Grid region -->

-----------------------------------------------------------------------------

Added this to the code on the STATE list box:

onchange="set_child_listbox(this, document.adv.range,Range,'Ranges');"

-----------------------------------------------------------------------------

When I publish the page and View the Source I can see all my Regions
appearing in the <HEAD> section. eg

var Region = new Array(

new Array(207,8,'ACT'),
new Array(143,4,'Adelaide'),
new Array(26,2,'Agnes Water/1770'),
new Array(161,5,'Albany'),
new Array(162,5,'Albany'),
new Array(110,3,'Apollo Bay'),


But I cant work out how to get the REGION list box to pick up the new
values.


regards
Damian

"peterr" <peterr@forum.codecharge> wrote in message
news:5420ac34c030b7@news.codecharge.com...
> That example was created specifically not to refresh the page. The page is
> NOT
> being refreshed when you select a category or product at
> http://examples.codecharge.com/CCSExamplePack2/Dependen...dentListBox.php
> and nothing becomes blank.
> That's why I pointed you to that example...
> _________________
> Peter R.
> YesSoftware Forums Moderator
> For product support please visit http://support.yessoftware.com
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


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.