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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please Explane - var parts = {front:1<<0, back:1<<1, cd:1<<2,} _____ [Resolved]

    Hello all... looking for alittle help, here.

    Can somone explane to me how this code works.

    :snip:
    PHP Code:
    var parts = {front:1<<0back:1<<1cd:1<<2cd2:1<<3cd3:1<<4cd4:1<<5inside:1<<6inlay:1<<7};

        var 
    titleCode elem.options[elem.selectedIndex].value;

        for (var 
    i in parts) {
            if(
    titleCode&parts[i]) {
                
    //alert(titleCode + " <>" + i);
                
    buffer += '[<a href="" onClick="titlePart.value=\''+i+'\';titleSubmit.focus();return false;" '
                
    buffer += 'onMouseOver="window.status=\''+ucFirst(i)+'\';return true;" onMouseOut="window.status=\'\';return true;">';
                
    buffer += '<strong>'+ucFirst(i)+'</strong></a>]&nbsp;&nbsp;';
            }
        } 
    :/snip:


    I know what the out come is and where the info is coming from, but dont know how it does its thing.
    Heres an example of what it does:

    elem.options[elem.selectedIndex].value is 197 (taking from a <select> box off a form)

    when looping through the 'parts' array (is that what it is ? thought arrays where defined differently in javascript) it will turn that 197 into;
    [Front] [Cd] [Inside] [Inlay] (takin from the 'parts' "array")

    The ucFirst() function just capitalize the first letter of the values held in the 'parts' array.

    Another example...
    If elem.options[elem.selectedIndex].value = 1 then it would return;
    [Front]
    If elem.options[elem.selectedIndex].value = 5 it would return;
    [Front] [Cd]

    Theres all different values for elem.options[elem.selectedIndex].value which display different combinations of the 'parts' array.

    So... whats going on with all that ???
    And what does the #<<# in the 'parts' array mean/do ?

    As you can see, I dont know too much about Javascript (im more of a simple PHP and VB programmer).
    The attach file is the javascript and a clip of the form that calls the script (so you can see it in action).

    Heres what im doing (if you care ).
    I have a VB program ive made for myself and a friend.
    With-in this program i 'Inet' a url and then i phase through the HTML source and pull out the info we want, then display that info in a listview. Noramly part of that info would work with the javascript, but im converting that to function under VB. Im not looking for the "javascript => VB" code here, i would just like to know excatly how the code above translates the numbers into the words and what the #<<# does.


    Hope that made sense, thanks for any help.
    Attached Files Attached Files
    Last edited by Misspell; 09-23-2005 at 07:35 AM. Reason: Resolved - Changed Title Of Thread

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Location
    Toronto, ON, Canada
    Posts
    231
    Thanks
    0
    Thanked 0 Times in 0 Posts
    And what does the #<<# in the 'parts' array mean/do ?
    x << y is binary left shift (shift x, y times to the left)

    as result:
    parts.front == 1
    ...
    ...
    ...
    parts.inlay == 128

    here it is as 2^n (2^0 == 1, 2^7 == 128)
    rm -f /

  • #3
    New to the CF scene
    Join Date
    Sep 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thank You

    Thank you so much, rm-f.

    Like i said... im a simple programer so i had to do alittle diggin to get an understanding of Binary, but now i know enough to get me over this hump; thank you.

    This link helped me alot, maybe it will help others...
    http://www.devarticles.com/c/a/JavaS...ors-continued/

    You have saved me so much time and typing.
    As of now my VB app has a bunch of IF Statments that check the 'titleCode' ID then manuly (hard-coded) the result. Now im gonna change it to a ID -> Binary convertion and then pull the info (Front, CD, Inside, Inlay) out of an array.

    Thanks again !


  •  

    Posting Permissions

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