Total members 11893 |It is currently Thu Nov 14, 2024 6:01 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka



Go to page 1, 2  Next


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.
---------------------
javascript 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.
-----------------------
javascript 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[i] = null;

}

prompt = (itemArray != null) ? goodPrompt : badPrompt;

if (prompt == null) {

j = 0;

}

else {

selectCtrl.options[0] = new Option(prompt);

j = 1;

}

if (itemArray != null) {

// add new items

for (i = 0; i < itemArray.length; 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 drop-down?




Author:
Newbie
User avatar Posts: 6
Have thanks: 0 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 :( !!!

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Yes.
The original code can be see here..
Code:
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.


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 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 ?

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Correct! The Problem is filling in the selection...

The database is queried via SSI (http://surf2saveinc.com/cgi-bin/coupons ... Automotive)

That gives us the array...

I need the array to fill in the <select> options in the dropdown menu.

Dazed


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 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 !

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 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?


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 time

you can use Onload event .

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time

Any ideas on the script to turn the array to options?


Author:
Newbie
User avatar Posts: 6
Have thanks: 0 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;
  }

</script>
<body onload="javascript: FillSelection();">

<div id="divselection">
<select id="myoptions" >

</select>
</div>





</body>

</html>



_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

  Related Posts  to : Populating Dropdown..
 POPULATING DROPDOWN IN MY DATABASE USING PHP     -  
 Dropdown list in ASP.NET - How to get value selected     -  









Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com