Results 1 to 2 of 2

Thread: JavaScript: Can some explane what this code is doing... [Resolved]

  1. #1

    Thread Starter
    Lively Member Misspell's Avatar
    Join Date
    Mar 2002
    Location
    Located
    Posts
    69

    JavaScript: Can some explane what this code is doing... [Resolved]

    Can somone explane to me how this code works.

    :snip:
    HTML Code:
    var parts = {front:1<<0, back:1<<1, cd:1<<2, cd2:1<<3, cd3:1<<4, cd4:1<<5, inside:1<<6, inlay: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;" '; // set part to property name
    			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 (???) 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.

    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 'part' array.

    And what does the #<<# in the 'parts' array mean/do ?

    As you can see, I dont know too much about Javascript.
    The attach file is the javascript and a clip of the forum 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; Sep 23rd, 2005 at 02:22 AM. Reason: Resolved - Changed Title Of Thread

    ~ What was once an opinion, became a fact, to be later proven wrong... ~

  2. #2

    Thread Starter
    Lively Member Misspell's Avatar
    Join Date
    Mar 2002
    Location
    Located
    Posts
    69

    Resolved

    Posted this questions on another board and heres the responce that helped.

    Quote Originally Posted by Misspell
    And what does the #<<# in the 'parts' array mean/do ?
    Quote Originally Posted by rm-f
    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)

    Since i was not familur with Binary, this link helped:
    http://www.devarticles.com/c/a/JavaS...ors-continued/


    So for my VB app i just convered the 'titleCode' ID to binary, held the 'parts' variable in an array and looped Mid(ByteToBin(titleCode_ID), x, 1) (looped to see what was "on/1" and "off/0") then compaired the 1's and 0's to my array.

    Thouhgt i would post it here incase somone else was wondering.


    _
    Last edited by Misspell; Sep 23rd, 2005 at 02:24 AM. Reason: typo's

    ~ What was once an opinion, became a fact, to be later proven wrong... ~

Posting Permissions

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



Click Here to Expand Forum to Full Width