Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation how to map one array element to another array element?

    hi..
    since i'm still new in programming..i would like to ask anyone's opinion on my problem with javascript array.

    if let say i have 2 arrays :

    var name = ["Mary","Adam","Aziz"]
    var id = ["84572","77617","96432"]


    how cam i map Mary to 84572 and so on..?

    please..i'm really stuck in here..

    thanks

  • #2
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well, "Mary" and "84572" have the same index in the array, which is 0.

    If that doesn't answer your question, then you will need to give us more information.
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #3
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Mybe using new objects:
    PHP Code:
    <script type="text/javascript">
    var 
    name = ["Mary","Adam","Aziz"]
    var 
    id = ["84572","77617","96432"]
    for(var 
    i=0;i<name.length;i++){
    window[name[i]]={'id':id[i]}
    }
    alert('Mary\'s id= '+Mary.id+' Adam\'s id= '+Adam.id+' Aziz\'s id= '+Aziz.id)
    </script> 
    But, as Kravvitz said, give us more details about your aim.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #4
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    what i wanted to do is to produce a code where user should enter "unit" in strings (eg IT Dept) and the system should be able to interpret the "unit" into a single character (eg IT Dept == 'A') whenever the user click on "VERIFY CODE" button and the character 'A' (in this case) should appear in one textbox named "unitcode" which is concatenated with constant 'J0020'.
    i've tried using the if..else function
    eg.
    function verify_code()
    {
    if (unit = "IT Dept)
    unitcode == 'A';
    else (unit = "Engineering Dept)
    unitcode == 'B';
    else.....so on...
    }
    document.reka_kursus.unitcode.value=('J0020' + unitcode);

    but the problem is still when user clicks "VERIFY CODE" button, the system will return the whole list of code in character
    (eg: J0020A,B,C,D,E,F.....bla.bla..)

    please..this is not the output i want.
    Thanks to everyone who is willing to help me..

  • #5
    Senior Coder
    Join Date
    Feb 2006
    Location
    USA
    Posts
    1,013
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Without seeing your actual code it's difficult to help.

    In the following code snippet you have "=" and "==" backwards.
    Code:
    if (unit = "IT Dept)
    unitcode == 'A';
    else (unit = "Engineering Dept)
    unitcode == 'B';
    Learn CSS. | SSI | PHP includes | X/HTML Validator | CSS validator | Dynamic Site Solutions
    Java != JavaScript && JScript != JavaScript
    Design/program for Firefox (and/or Opera), apply fixes for IE, not the other way around.

  • #6
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <head>
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    var arrItems1 = ["PPLB","Management","Administration","Finance","Corporate System","Computer","Electrical","Electronic & Instrument","Mechanical","Safety","Welding","Non Destructive Testing","Operation","Others","Overhead","Cable","Substation","Others","Overhead","Cable","Substatio n","Others"]
    var arrItemsGrp1 = ["11","21","21","21","21","31","41","41","41","41","41","41","41","41","51","51","51","51","61","61", "61","61"]
    var arrunitcode = ["R","A","B","C","D","S","E","F","G","H","I","J","K","V","O","P","Q","T","L","M","N","U"]

    function verify_code(arrItems1,arrItemsGrp1,arrunitcode) //to be executed when user click "VERIFY CODE" button
    {
    for(var i=0;i<arrItems1.length;i++)
    {
    window[arrItems1[i]]={'arrunitcode':arrunitcode[i]}
    }
    document.reka_kursus.kod_kursusb.value=('J0020'+arrItems1.arrunitcode);
    }
    // -->
    </script>
    </head>

    <body>
    <form name="reka_kursus" method="POST">

    <p align="left"><b><font color="#003399" face="Arial">&nbsp; Kod Kursus :</font>
    &nbsp;<input type="text" name="kod_kursusb" size="11" maxlength="11">&nbsp;</p>
    <p align=center><input type="button" value="VERIFY CODE" onclick="verify_code();" name="VERIFY CODE">


    /* for now, this is my real coding */
    Last edited by shy84may; 05-09-2006 at 04:36 AM.

  • #7
    New to the CF scene
    Join Date
    May 2006
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    for now..the output doesn't appear when user click that button..

    since i am so new in programming, i can't debug my own program..

    thanks to kravvitz for ur help..


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •