Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Script using array

 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
() is calling a method or function

[] is calling an index of an array or object

Eric
 
Aravind Prasad
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
reply
    Bookmark Topic Watch Topic
  • New Topic