473,609 Members | 2,263 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I avoid adopting of values in other variable within an array?

Exequiel
288 Contributor
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Untitled Document</title>
  4. <script type="text/javascript">
  5. function ikel()
  6. {
  7.     var sel = document.ikki.sel.value;
  8.  
  9.     if(sel=="T-shirt")
  10.     {         
  11.         var shirt = ["bench","cotton republic"];
  12.         var shirt_len=shirt.length;
  13.         var el=0;
  14.         for(var ii=0; ii<shirt_len; ii++)
  15.         {
  16.              document.ikki.brand.options[ii]=new Option(shirt[ii], ii);            
  17.             }
  18.         return sel;
  19.     }//end of if satatement T-shirt
  20.  
  21.     if(sel=="CARS")
  22.     {         
  23.         var car = ["Toyota","Honda", "Forbes", "Mitsubishi", "Kia", "Nissan"];
  24.         var car_len=car.length;
  25.         var cc=0;
  26.         for(var cc=0; cc<car_len; cc++)
  27.         {
  28.              document.ikki.brand.options[cc]=new Option(car[cc], cc);            
  29.             }
  30.          return sel;
  31.     }//end of if satatement Cars
  32.  
  33.     if(sel=="Porn Site")
  34.     {         
  35.         var por = ["Mofos.com","Naughty America.com", "Erotica.com"];
  36.         var por_len=por.length;
  37.         var xx=0;
  38.         for(var xx=0; xx<por_len; xx++)
  39.         {
  40.              document.ikki.brand.options[xx]=new Option(por[xx], xx);            
  41.             }
  42.         return sel; 
  43.     }//end of if satatement Cars
  44.  
  45. }//end of function ikel
  46. window.onload=ikel;
  47. </script>
  48. </head>
  49. <body>
  50. <form name="ikki">
  51. Menu
  52.         <select name="sel"  onclick="ikel()" id="selected" >
  53.                    <option >T-shirt</option>
  54.                    <option >CARS</option>
  55.                    <option >Porn Site</option> 
  56.              </select> 
  57.           Brand              
  58.               <select name="brand" onchange="ikel()" ><!--option output--></select> 
  59. </form>
  60. </body>
  61. </html>
My problem here is that some values in longest array variable (like CARS for select tag Menu) adopted by the select tag (like the select tag for T-shirt in brand menu). Please response...
you can run the code and please observe...
Jul 9 '12 #1
4 1866
ariful alam
185 New Member
just use the following line to remove all the previous options in the select tag before all for loop those binds new data to 2nd combo box:

Expand|Select|Wrap|Line Numbers
  1. document.ikki.brand.options.length=0;
  2.  
Jul 9 '12 #2
Exequiel
288 Contributor
thank you for that code . . . your great . . . hehe... I'm just a beginner in javascript... thank you very much... see you for my ext questions.... haha god bless.. :)
Jul 10 '12 #3
Exequiel
288 Contributor
I have A question... How can I select the content of brand here...Example : when I selected in the Menu like for Example CARS, the Options will display in "Brand", but when I started to select the 2nd to the last option, the only value that appears is the first value like "Toyota"...
Jul 12 '12 #4
ariful alam
185 New Member
in your HTML you have line like following:
Expand|Select|Wrap|Line Numbers
  1. <select name="brand" onchange="ikel()" ><!--option output--></select>
here, "onchange" Event creates the problem for you. when ever you click an item in "sel" select tag the values of "brand" select change because of "ikel()" function in "sel"'s "onclick" event.

similarly, whenever you select an option from "brand" item, it calls the "ikel()" function that used in "onchange" Event of "brand".

So, remove the 'onchange="ikel ()"' from the "brand" select tag.

Hope you understand. :)
Jul 12 '12 #5

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

Similar topics

9
2436
by: dr. zoidberg | last post by:
Is it possible to put Variable in Array? Here is what I need: $array = Array($a,$b); $a = 'something'; $b = 'something else'; foreach ($array as $val) { echo "$val"; }
18
2934
by: Xiangliang Meng | last post by:
Hi. void setValue(int n) { int size = getValueLength(); int buffer_p; if (buffer_p) { ....
1
1410
by: Wolfram Heinz | last post by:
Hi there, How can I avoid type-conversion (object variable --> string) when passing an object variable to a function? Example: --> catch(myerrorobject) alert(myerrorobject.filename); { my_function('bla: ',myerrorobject);
5
14101
by: dam_fool_2003 | last post by:
Hai, I studied that the array size is fixed. But I come across a word called "variable length array". Is it possible to change the array size? So I tried the following: #include<stdio.h> #include<stdlib.h> int main(void) { int y = { 7, 9,10},i; for (;i<20;i++)
10
6677
by: Adam Warner | last post by:
Hi all, With this structure that records the length of an array of pointers as its first member: struct array { ptrdiff_t length; void *ptr; };
8
1867
by: Fernando Barsoba | last post by:
Hi, I decided to start a new topic about my memory allocation question. One of the answers was that variable length arrays are possible using C99. I found this topic that also mentions it. http://groups.google.com/group/comp.lang.c/browse_frm/thread/f7285cf1ffb172c3/f5335d22d6e6fb34?q=variable+length+array&rnum=2#f5335d22d6e6fb34 I did some test, but I get strange results:
1
9951
by: moonriver | last post by:
I intend to generate a variable-length array, similar to link lists in plain C. For example, I define the following array int a Initially I assign 5 elements to the array as a = new int for( k = 0; k < 5; k++ a = k
8
1778
by: lovecreatesbeauty | last post by:
Hello experts, I have seen following the code snippet given by Marc Boyer (with slight changes by me for a better format), and have doubts on it. I am so grateful if you can give me your kindly help and hints on this problem. 1. Does the function call `foo(3, 3, tab);' refer to the data outside the array `int tab;'. The available subscription for a 3X3 2-D array should be 0..2 X 0..2, I think.
3
1059
by: Mrozu | last post by:
Hi How can I include in name of my variable value of other variable? I have following code: For x = 0 To 10 Dim column As New DataGridTextBoxColumn column.MappingName = magazyny(x)
6
5056
by: Dan | last post by:
Excuse me if i'm being a bit thick here, but is it possible to reference a server side variable within an embedded js source file. For example, my test.js file contains alert('<%=tmpVar%>'); and my aspx page contains:- <script type="text/javascript" src="test.js">
0
8121
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8559
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8519
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8386
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6987
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6050
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4068
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1644
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.