473,484 Members | 1,718 Online
Bytes | Software Development & Data Engineering Community
Create 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 1860
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
2423
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
2912
by: Xiangliang Meng | last post by:
Hi. void setValue(int n) { int size = getValueLength(); int buffer_p; if (buffer_p) { ....
1
1402
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); {...
5
14091
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>...
10
6660
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
1860
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. ...
1
9940
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...
8
1761
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...
3
1046
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
5027
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%>'); ...
0
6953
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
7105
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
7214
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...
1
4845
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...
0
3046
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3041
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1359
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 ...
1
592
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
235
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.