GeeCON Prague 2014*
The moose likes HTML, CSS and JavaScript and the fly likes Script using array Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Script using array " Watch "Script using array " New topic
Author

Script using array

Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Hello Ranchers..
How can i create the java script using the array objects

<script language="JavaScript1.4" type="text/javascript">
function test(i)
{
//alert(i);
var val = document.menuform1.menu(i).value;
alert(val);
}
</script>


menu(i) is the name of the combo box.
there are 8 combo boxes created dynamically..
and i've give the code like this

<select name="menu[#i#]" onchange="test(#i#)">

and when i run the page.. it is showing error..

How can i do the code..

Please help me ranchers..

Thanks in advance
regards

Aravind
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
() is calling a method or function

[] is calling an index of an array or object

Eric
Aravind Prasad
Ranch Hand

Joined: Dec 28, 2005
Posts: 263
Thanks for the reply ERIC

but i'm not completely fixed with the issues

the code here is like this

-------------------------------------------------------------------
<TD class=boxlistAfull width="20%">  <SELECT
class=text onchange=test(1) name=menu[1]> <OPTION
value=5 selected></OPTION> <OPTION
value=0>Admin</OPTION> <OPTION
value=1>Manager</OPTION> <OPTION
value=2>Supervisor</OPTION> <OPTION
value=3>User</OPTION> <OPTION
value=4>SuperClient</OPTION> <OPTION
value=5>Client</OPTION></SELECT> </TD>


<TD class=boxlistAfull width="20%">  <SELECT
class=text onchange=test(4) name=menu[4]> <OPTION
value=5 selected></OPTION> <OPTION
value=0>Admin</OPTION> <OPTION
value=1>Manager</OPTION> <OPTION
value=2>Supervisor</OPTION> <OPTION
value=3>User</OPTION> <OPTION
value=4>SuperClient</OPTION> <OPTION
value=5>Client</OPTION></SELECT> </TD>

-------------------------------------------------------------------

this code is creating dynamically and the script i'm using for getting the value of the combo i'm getting is like this

-----------------------------------------------------------------------
<SCRIPT language=JavaScript1.4 type=text/javascript>
function test(i)
{
var val = i;
alert(val);
alert(document.menuform1.menu[1].value);
//var val = document.menuform1.menu[i].value;
//alert(val);
//alert(document.menuform1.menu[i].value);
}
</SCRIPT>

------------------------------------------------------------------------
How to get the value of the combo box.. i selected..

Please help me

thanks in advance

regards
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
if you are using a [] in the name, than you need to reference it with the form element array

document.formName.elements["yourName[1]"].value

(You are lucky my pts woke me up at 4AM)

Eric
 
jQuery in Action, 2nd edition
 
subject: Script using array