Total members 10262 | Gratitudes |It is currently Thu May 24, 2012 10:02 am Login / Join Codemiles


All times are UTC [ DST ]




Post new topic Reply to topic  Quick reply  [ 11 posts ]  Go to page 1, 2  Next
Author Question
 Question subject: Populating Dropdown..
PostPosted: Tue Jan 27, 2009 8:42 pm 
Offline
Newbie
User avatar

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[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 dropdown?

Thanks!
Dazed


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Tue Jan 27, 2009 9:25 pm 
Offline
Mastermind
User avatar

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 )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Tue Jan 27, 2009 9:52 pm 
Offline
Newbie
User avatar

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.


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Tue Jan 27, 2009 10:10 pm 
Offline
Mastermind
User avatar

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 )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Wed Jan 28, 2009 12:54 am 
Offline
Newbie
User avatar

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...

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


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Wed Jan 28, 2009 9:40 pm 
Offline
Mastermind
User avatar

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 )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Wed Jan 28, 2009 9:57 pm 
Offline
Newbie
User avatar

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?


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Wed Jan 28, 2009 10:16 pm 
Offline
Mastermind
User avatar

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 )


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Wed Jan 28, 2009 10:21 pm 
Offline
Newbie
User avatar

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?


TOP
 Profile Send private message  
Reply with quote  
 Question subject: Re: Populating Dropdown..
PostPosted: Thu Jan 29, 2009 12:15 am 
Offline
Mastermind
User avatar

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;
  }

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

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

</select>
</div>





</body>

</html>


_________________
Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )


TOP
 Profile Send private message  
Reply with quote  
Post new topic Reply to topic Quick reply  [ 11 posts ]  Go to page 1, 2  Next
Quick reply


  

 Similar topics
 Dropdown list in ASP.NET - How to get value selected
 POPULATING DROPDOWN IN MY DATABASE USING PHP

All times are UTC [ DST ]


Users browsing similar posts

Users browsing this forum: No registered users and 1 guest



Jump to:  
Previous Question | Next Question 




Home
General Talks
Finished Projects
Code Library
Games
Tutorials

Java
C/C++
C-sharp
php
Script
JSP/Servlets
Ajax
ASP/ASP.net
Google SEO
Database
Communications
Phpbb3 styles
Photoshop tutorials
Flash tutorials
Find a job






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team