Joined: Tue Jan 27, 2009 8:12 pm Posts: 6 Has thanked: 0 time Have thanks: 0 time
Alrighty.. I have a database that generates this code for a dropdown list (B) based on the selection of a previous dropdown list (A)..
I would like to use this array to populate a single dropdown menu for a different page on page load.
Here is the array the database generates. ---------------------
Code:
team = new Array( new Array(new Array(""), new Array("Automotive Service & Repair/Oil Change"), new Array("Car Wash/Detailing Service"), new Array("Tire Stores"), new Array("Transmission Centers") ), new Array("")
),
----------------------
below is how the full script on the original (2 dropdown) page. -----------------------
Code:
<script langauge="javascript"> team = new Array( new Array(new Array(""), new Array("Automotive Service & Repair/Oil Change"), new Array("Car Wash/Detailing Service"), new Array("Tire Stores"), new Array("Transmission Centers") ), new Array("")
),
function fillSelectFromArray(selectCtrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length; i >= 0; i--) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].value = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].selected = true;
}
}
// End -->
</script>
------------------------------ So, could the original script be modified to populate a single dropdown?
Thanks! Dazed
msi_333
Question subject: Re: Populating Dropdown..
Posted: Tue Jan 27, 2009 9:25 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
I tried to understand your code ,your code fill some <select> option right ? based on some condition right ?
But the problem not clear to me !!!
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
dazed
Question subject: Re: Populating Dropdown..
Posted: Tue Jan 27, 2009 9:52 pm
Joined: Tue Jan 27, 2009 8:12 pm Posts: 6 Has thanked: 0 time Have thanks: 0 time
Yes. The original code can be see here.. http://www.surf2saveinc.com/catlist5.shtml The Array on that page populates the subcategory list when a selection is made to the category list.
On a new page. I would query the database for a category, and have the "Array" populate a subcategory menu on page load.
I already have the database creating the array, and can include it in the script via SSI, I just don't know how to rewrite the script to populate the <select> options onload.
msi_333
Question subject: Re: Populating Dropdown..
Posted: Tue Jan 27, 2009 10:10 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
so you want to choose category then press a button , then you go to a new window where you can see the corresponding subcategories .In that case you will not need javascript .
another case are you using dynamic web programming language ? sure you are , like jsp ,php, asp.net to make connection to database and get categories . is your problem in filling the <selection> by the result of the query ?
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
dazed
Question subject: Re: Populating Dropdown..
Posted: Wed Jan 28, 2009 12:54 am
Joined: Tue Jan 27, 2009 8:12 pm Posts: 6 Has thanked: 0 time Have thanks: 0 time
Correct! The Problem is filling in the selection...
I need the array to fill in the <select> options in the dropdown menu.
Dazed
msi_333
Question subject: Re: Populating Dropdown..
Posted: Wed Jan 28, 2009 9:40 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
Why don't you fill it based on the parameter sent from the category <selection > .
What is SSI ? i saw the link i saw a code for creating array of arrays . I think it is the category list .
Javascript is used to handle data not to fill from database !
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
dazed
Question subject: Re: Populating Dropdown..
Posted: Wed Jan 28, 2009 9:57 pm
Joined: Tue Jan 27, 2009 8:12 pm Posts: 6 Has thanked: 0 time Have thanks: 0 time
SSI = Server Side Include..
I think we've gotten off track, and it probably is my fault. :-)
I'll start over.
I have this array
Code:
new Array(new Array(""), new Array("Cruises"), new Array("Honeymoons"), new Array("Tours/Land Packages") ),
I need it to populate a <select> option list on page load. ie: <option></option> <option>Cruises</option> <option>Honeymoons</option> <option>Tours/Land Packages</option>
Any ideas?
msi_333
Question subject: Re: Populating Dropdown..
Posted: Wed Jan 28, 2009 10:16 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
you can use Onload event .
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )
dazed
Question subject: Re: Populating Dropdown..
Posted: Wed Jan 28, 2009 10:21 pm
Joined: Tue Jan 27, 2009 8:12 pm Posts: 6 Has thanked: 0 time Have thanks: 0 time
Any ideas on the script to turn the array to options?
msi_333
Question subject: Re: Populating Dropdown..
Posted: Thu Jan 29, 2009 12:15 am
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2279 Location: Earth Has thanked: 39 time Have thanks: 61 time
I made this code for you :
Code:
<html> <script type="text/javascript">
function FillSelection() {
var divselection = document.getElementById('divselection');
team = new Array( new Array(new Array(""), new Array("Automotive Service & Repair/Oil Change"), new Array("Car Wash/Detailing Service"), new Array("Tire Stores"), new Array("Transmission Centers")),new Array("") ); document.getElementById('subject'); var myoptions="<select id='myoptions' >"; alert(team[0].length); for(var i=0;i<team[0].length;i++) { myoptions+="<option>"+team[0][i]+"</option>"; alert(team[0][i]); } myoptions+="</select>"; divselection.innerHTML=myoptions; }