I need to build an array from the value e.g.
array = form value
| SitePoint Sponsor |
I need to build an array from the value e.g.
array = form value
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
e.g.
array = new array()
array[0] = "jo";
array[1] = "no";
value=array
looad array = value
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
Now I have some real time to myself to ask explain heres my example
<SCRIPT>
woof =new Array()
meow =new Array()
squeak =new Array()
function load_array()
{
var animal = array(document.form1.ani.options.selectIndex.value);
}
</SCRIPT>
<FORM name="form1">
<SELECT onChange="load_array()">
<OPTION value="woof">Dogs</OPTION>
<OPTION value="meow">Cats</OPTION>
<OPTION value="squeak">Mouse</OPTION>
</SELECT>
</FORM>
any ideas
help will be appriciated
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
This function will do what you want.
Code:function get_val(){ obj = document.forms[0].elements[0]; //The dropdown sel=[]; sel[0]=obj[obj.selectedIndex].value; //Option Value sel[1]=obj[obj.selectedIndex].text; //Option Text return sel; }
Drinky
This is a fully working example, cut and paste into a new blank html doc. When you select a value in either text box it will show you what you picked in a message box
Code:<html> <head> <title>Select info demo</title> <script> function get_val(obj){ sel=[]; sel[0]=obj[obj.selectedIndex].value; //Option Value sel[1]=obj[obj.selectedIndex].text; //Option Text //return sel; alert('Value:\t'+sel[0]+'\nText:\t'+sel[1]) } </script> </head> <body> <form> <select onchange="get_val(this)"> <option value="val0">text0</option> <option value="val1">text1</option> <option value="val2">text2</option> <option value="val3">text3</option> </select> <select onchange="get_val(this)"> <option value="val4">text4</option> <option value="val5">text5</option> <option value="val6">text6</option> <option value="val7">text7</option> </select> </form> </body> </html>
Drinky
I mean like the values are
woof
meow
and three arrays with them
woof[]
google[]
meow[]
and I want to know how to get the array that is named after the value so I can use it to write a combo-box control
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
You can use the eval(String) function to pickup objects variables and execute functions whose names correspond to the supplied string.
Off the top of my head this code should return your arrays based on supplying the words woof, google, meow to it.
Code:var woof=[] var google=[] var meow=[] function return_array(val){ if(typeof eval(val) is "object"){ return eval(val); } else { return false; } } //useage woofArray = return_array('woof');
Drinky
My whole page it still isn't working
any ideas why?Code:<HTML> <HEAD> <TITLE>LANGUAGE</TITLE> <SCRIPT language="javascript"> <!--hide from old grannies var volks = new Array(); volks[0] = "Beatle"; volks[1] = "Sharan"; volks[2] = "Passat"; var alltogether; function return_array(val){ if(typeof eval(val) is "object"){ return eval(val); } else { return false; } } function add_options(typelist) { if( typelist == "model" ) { var typelist = window.document.boogle.google; var dropdownchange = window.document.boogle.noodle; } var typelist = return_array(typelist[typelist.selectedIndex].value); for(var i=0;i <dropdownchange.length ; i++) { dropdownchange.options[i].text = typelist[i]; } while(dropdownchange.length <typelist.length) { var new_option = new Option; new_option.text = typelist[dropdownchange.length]; dropdownchange.options[dropdownchange.length]= new_option; } } //let them put there glasses on --> </SCRIPT> </HEAD> <BODY> <FORM name="boogle" onSubmit="return false;"> <SELECT name="google" onChange="add_options("model");"> <OPTION value="make">---Make---</OPTION> <OPTION value="volks">Volkswagen</OPTION> </SELECT> <SELECT name="noodle"> <OPTION value="model">---Model---</OPTION> </SELECT> <INPUT type="submit" value="Search"> </FORM> </BODY> </HTML>
Last edited by Da Mouse; Aug 30, 2002 at 05:45.
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
Any help with this?
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
::Bump::
I really need an answer for this
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()





I can definately help you with the array thingy - if it's not already solved.
Just to clarify though:
What part of the page is not working ?
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---
When I select the first box the second one does nuttin
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()





Put some alerts in the function and function logic to see what it's doing.
Flawless
---=| If you're going to buy a pet - get a Shetland Giraffe |=---
Should've beenCode:(typeof eval(val) is "object")
got that from a different forumCode:(typeof eval(val) == "object")
JavaScript WorkShop
go there for ANY javascript needs its excellent
I am DaMouse
Nobody can beat me so long as I'm stubborn -DaMouse
![]()
![]()
![]()
Squeak
![]()
![]()
![]()
My faultOriginally posted by Da Mouse
Should've beenCode:(typeof eval(val) is "object")
got that from a different forumCode:(typeof eval(val) == "object")
JavaScript WorkShop
go there for ANY javascript needs its excellentanswering questions while tired
![]()
Drinky
Bookmarks