473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

how to display an item from indexed array in a second dropdown

Hi
I'm a php/mysql developer and struggle when it comes to javascript !
I've looked all over for a solution but am rubbish at adapting javascript

I've got two select dropdowns in a form
The first picks an item and the second needs to auto update to show which colours that item comes in

(I've done it before by resubmitting the page with php via an auto submit - which is ugly)

Ok - I've managed to convert all my colours into a multi dimensional javascript array, so it looks like:
Expand|Select|Wrap|Line Numbers
  1. colwayarray[22] = '<OPTION VALUE=18 >Daisy pink</OPTION><OPTION VALUE=17 >Pale aqua</OPTION>'; 
  2.  colwayarray[26] = '<OPTION VALUE=22 >Sea splash</OPTION><OPTION VALUE=19 >Tangerine</OPTION>'; 
  3.  
the index value corresponds to the index value of the chosen item from the first select
(the first select is built when the php builds the page )

um - now I havent got a clue how to get the second dropdown to autopopulate when the first dropdown is changed with an
onclick -
I think it must be fairly simple ..
I can access the required option string with this
Expand|Select|Wrap|Line Numbers
  1. <script language=javascript>
  2. document.write(colwayarray[66]);
  3. </script>
but how do I put it in the select dropdown

any help much appreciated !
Apr 25 '07 #1
6 1711
oh no, my poor thread is going to be one of those unloved and lonely threads with no replies

right I've got to this stage now:

the first select does this:

Expand|Select|Wrap|Line Numbers
  1. <select name='match_garm' id='match_garm' onChange="changeText('match_garm');">
the top of the page js is:

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function changeText(elemid) {
  3. var ind = document.getElementById(elemid).selectedindex;
  4. document.getElementById("m_cway").innerHTML=colwayarray[ind];
  5. document.getElementById("m_cway2").innerHTML=colwayarray[ind];
  6. }
  7. </script>
the two items changed are for testing - m_cway is the second select, m_cway2 is just a div to show if its getting anything

now when I change the first select my test div displays "undefined"

but if I hard code the function with an index number like so:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("m_cway").innerHTML=colwayarray[54];
  2. document.getElementById("m_cway2").innerHTML=colwayarray[54];
  3.  
then both items work perfectly.. - the select populates and the div reads out the text

what am I doing wrong?
Apr 26 '07 #2
isnt it wonderful how typing the qusetion often makes you think again..

I did this :

var ind = document.getElementById(elemid).value;

and it works
Apr 26 '07 #3
hi - need to bump my question again

the above solution works in Firefox but does not work in IE 6 - the (php generated) js array seems to be working ok - I just cant get the select to populate with an element of it

I'd be really grateful for any suggestions at all !
May 2 '07 #4
acoder
16,027 Expert Mod 8TB
Sorry no-one had a look at your thread. I was a bit busy last week.

See this link.
May 3 '07 #5
sorted
headerjs:
Expand|Select|Wrap|Line Numbers
  1. var ind = document.getElementById('match_garm').value;
  2. var wrapdiv = document.getElementById("wrapdiv");
  3. wrapdiv.innerHTML = "<select name='m_cway' id='m_cway'>"+colwayarray[ind]+"</select>";
then wrap the second select in a div with the id wrapdiv
May 3 '07 #6
iam_clint
1,208 Expert 1GB
wow sorry I didn't see your post I coulda had a solution to you pretty quck.
May 3 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: passion_to_be_free | last post by:
This is probably simple, but I can't seem to find it anywhere. I have have some values stored in javascript variables. I have a <select> dropdown list whose options correspond to these values. I...
8
by: J. B. Moreno | last post by:
What's the best (i.e. fastest) way to find out if an array contains a given value? Other than looping, the only way I know to do it is to use an associative array/hash instead.... Is there a...
5
by: news | last post by:
Using php.net I got this far, and so far so good! But I can't fenagle it quite the way I need to. I'm creating an array (which I didn't know how to do before today, so a success for me *g*): ...
4
by: dixie | last post by:
I have a table called "tblParticipants" with a field called "ID", which must be indexed with No duplicates allowed. I am looking for a way of doing in vba a small if ..then ..else .. routine that...
2
by: farseer | last post by:
Hi, I have a combobox who's data source i set to an array of objects (call it MyObject). these objects have get properties: key, value, descr. i set ValueMember to "key", DisplayMember to...
4
by: Merdaad | last post by:
My drop down list is populated from a static array in my codebehind (c#) code. I set the selected index based on some known values(from DB), when the screen shows up, dropdown list shows that the...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
6
by: yasodhai | last post by:
Hi, I used a dropdown control which is binded to a datagrid control. I passed the values to the dropdownlist from the database using a function as follows in the aspx itself. <asp:DropDownList...
12
by: active | last post by:
I've been looking on the Internet for a way to convert a DIB to a Bitmap without success. Now I'm wondering if that is the approach I should be taking. All I want to do is display the DIB or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.