JavaScript - Questions About Good-looking Code / Improving My Skills
Hello,
I am trying to understand something I often see in other's code: Code: (function(){ //do something })(); a) Why is the function wrapped into parenthesis? b) Why are there parenthesis at the very end of the snippet? A variant that is also mysterious to me is: Code: (function(){ //do something })(document.documentElement); Why the document.documentElement in parenthesis? Regards, -jj. Similar TutorialsI recently read a couple blogs that listed some points for writing better Javascript code. Several points applied to the code I write, so they caught my eye. For example, Quote: Use === instead of == and Quote: Use [] Instead of New Array() All of my programs are for numerical computations. Input comes from a textarea box, it is converted to floats, then it is put in arrays, compared, manipulated, etc. For example, Code: rawArray = rawtextareaString.split(/\s+/g); . . . tempx = parseFloat(rawArray[k]); . . . sqAMatrix[i][j] = tempx; . . . Before I rush out and revise all my code to incorporate these suggestions, are there are concerns I should be aware of? Gotchas? Compatibility issues? Should I even bother? Hi, I've just starting my way with javascript and I have 2 questions: 1 - what is the different between *.html file and *.js file ? 2 - How can I run javascript file from cmd command line ? ( I have Win' XP ) Thanks in Advanced my code: <html> <head> <title>Learning Javascript</title> </head> <body> <p>Hello World! </body> </html> An intranet site I've been working on is getting demo'd next week and I'm pretty proud of its functionality. It looks pretty good too but the biggest eyesore are the listboxes. The navigation column on the left of the page has 3 large listboxes, each one housing between a dozen and several hundred options related to employees, meeting rooms, etc. For that sort of directory functionality a listbox is pretty much the only way to go. The annoying part is that listboxes haven't really changed in 20 years. I sure wish IE supported listbox background images but since it doesn't I'm left with changing the border or changing the background color. I don't know if you've played with that but a listbox looks just as cheap with a mono blue, red, or purple background as it does with white Does anyone know some code for livening it up? Thanks. Frequent reader, usually find my code fixes via Google... so first post, but I've been programming for a while... I've always been horrible at JavaScript... Java was easier for me. anyways... My problem: I am building a website for my fire department that i am a member. here is what i have www. explosive supplements .com(header picture is a mockup, being worked on by a graphic artist) (spaced out for privacy, this domain is my testing website that i used to test my programming prototypes live without taking other sites offline.) My main issue is IE7 and IE8 in compatibility mode My Solution: I need to make a popup/warning to tell those running IE7 to update their browser to view the website and a popup/warning to tell those who are running compatibility mode in IE8 to turn it off to view the webpage properly. i thought about making a seperate template for IE7, but that still doesnt help with those running compatibility mode in IE8. Thanks for any help that you can give. So I am looking for a book that basically goes from the very basics to middle level of java programing, but one that is up to date, and that explains everything, not like some of the books that just throws code at you and expects you to understand why you are making the class public and why it extends javaplugins, just something in depth that really explains why for everything.
I am looking to add the load date by scrolling paginating but i am not sure if this will cause the site to dramatically load slower. http://www.9lessons.info/2009/07/loa...query-php.html That is what i was going to implement but unsure if i should. Any of you guys got any knowledge in this? Thanks Today, all major cell phone makers (exept apple) announced that they will support a common app standard based on html, css, and javascript. Article: http://news.yahoo.com/s/afp/20100215...owapplications This means that we can use our web skills to make applications for mobile phones. Previously, we would have to invest learning time into a closed-path system like the iPhone's Objective-C, or a minor player's API like webOS. Called BONDI, it's basically a webpage with some extra generic DOM handles for using system features like fetching contact lists, GPS, sending SMSs, playing a sound, etc. While I am not blown away by the demo widgets linked below, i realize they are little more than "hello world", as much actually as figuratively. I expect support and development to entrench around this simple standard, so more and more hardware features will gradually start working on more and more devices. It's the same notion as the JS/HTML software i wrote years ago for firefox that now works in IE8... Check it out: http://bondi.omtp.org/usebondi/Lists...Y/Gallery.aspx I encourage all to participate in developing for open source platforms like BONDI. While there's more money right now in iPhone, the future belongs to us. Don't support proprietary techs! Besides, i cannot imagine that Apple/some fan boy will not eventually add BONDI support to iPhones; they already have a browser! I just started learning javascript, and it'd be cool if I could find some kind of javascript reference site similar to php.net/manual with a quick reference search. After looking through google for a long while, all I could find was tutorial sites or reference books with the only way to navigate them is through boring tables of contents. Does such a place exist? Or what's the next best thing?
Can anybody recommend a good free uploader that allows multiple file selection at the same time? Any help appreciated! Hey guys, I'm new to the forum, just registered today. And I'm wondering whats the best javascript editor out there? I'm going to school for web development and I'm taking a javascript class next semester, the problem is the class is online so i have to teach myself. I have previous coding experience with html, css, actionscript 2 and coldfusion. I want to know whats the best editor out there is? I have used Dreamweaver for my previous coding and i don't like it. It feels to bloated and has way to much stuff i never use. Anyone want to share what they use? Make me a recommendation, it doesn't matter weather its for mac or pc. I have a macbook pro i use for school and i already have a a copy of adobe creative suite 5 for mac and Visual studio 2010 for windows. Anyone ever use visual studio for web development? I would really appreciate any help you can give me. Anyway thanks for reading my long post, and any advice is really appreciated. Thank You, Emiljan JavaScript functions must be called: A. from the server B. implicitly C. explicitly D. A and C, but not B. E. None of the above. JavaScript commands written outside of a function will be executed: A. by the server. B. implicitly. C. explicitly. D. never, they are ignored. E. None of the above. The best loop for iterating through an array is A. Enhanced For loop B. While C. Do Until D. Do While. E. None of the Above. JavaScript Arrays are always passed to functions? A. By Reference. B. By Value. C. Globally. D. As a string. E. None of the Above. The best way to execute JavaScript code when you first bring up a page is: A. onload event B. JavaScript code outside of any function. C. onstart event. D. All of the above. E. None of the Above. Write a JavaScript function to handle a callback: Assume the following input fields: <input type="text" id="lastName" name="lastName" /> <input type="text" id="firstName" name="firstName" /> <input type="text" id="phone" name="phone" /> <input type="text" id="email" name="email" /> A callback function will receive a pipe delimited string from the server as such: Last-name|first-name|phone#|email Example: Doe|Jane|415-555-1212|jane.doe@gmail.com The callback function is: function customer_Callback ( content ) { // use the split method to convert content to an array. // use document.getElementById() to get each of the above input fields. // populate from the array. } ----------------------------------------- I am having serious trouble with these problems, I beseech you! There will be a special prize to whoever answers correctly all these questions first. Thanks! 1. I am in the midst of making a website and doing a few things but am thinking of adding a log in section for members can i put a password directly on a video file? or do i have to do it to the page? 2. Also looking for a good provider to upload my site to, what does everything suggest for this? Thanks Hi again, I have 2 new questions for you all! 1.) *RESOLVED* 2.) So in this form: Code: <form name="form" action="email.php" method="post"> <div id="dynamicInput"> <br> <input type="checkbox" name="1" /><input type="text" name="i[]"> </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br> <input name="email" type="text"> <br /> A12098 <input name="verify" type="text"> <input name="submit" type="submit"> </form> I have a button that will add a form element to the form. In this case, it adds a checkbox and a text box. The name on the checkbox goes up from 1-30 (thats the max amount of fields that can be added) and the text box has a name of i[]. Is it possible for the user to click on the checkbox and the corresponding text box (the one next to the checkbox) will be disabled so editing is stopped? Then they could un-click it and it would be editable again. Thanks in advance! Hey everyone, I have a survey that I have been developing (with the help of people from this forum among others) that is nearing completion but still has a couple things to be worked out using JavaScript. For reference, here is a link to the survey: http://wri.eas.cornell.edu/weed_survey_site/index2.html Here is one issue that I'm having and I would appreciate any help: 1. on line 111, the label, id and value for each input needs to increase by one (i.e <label for='ValidCheckbox_01'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_01' value= '1'>" + i + "</label>, <label for='ValidCheckbox_02'><input type = 'checkbox' name = 'ValidCheckbox2' id= 'ValidCheckbox_02' value= '2'>" + i + "</label>, etc.) for each additional label. Hi all, This is a quickie. I'm a JavaScript newbie. I have had a crack programming with it but I need some questions answered to help my understanding. Please tell me the convention that governs the use of "" and '', because so many articles that I am finding in my learning journey are using them interchangeably and it is so confusing. For instance, but not limited to, take the id and value tags of an <input type=... of whatever. Is it best to use '' or "" for the labels you give? What is the convention governing the use of a ; (semicolon) because so many people use one where others do not. I'm under the impression it is an EOL terminator like in Bash, right? So it goes after declaring variables or after something within an if statement perhaps? Thanks QF Hi, I am currently having a problem with my code. It is pointing at a logical error somewhere as neither the error console in FireFox nor Firebug can detect any errors. The problem is getting the alert box to pop up when the user types in invalid letters or numbers for their respective functions. I guess it could be the Unicode coding for Internet Explorer or Mozilla, or maybe the validation is not getting called from the option list....Anyway here's my code so far: <script type="text/javascript"> /* <![CDATA[ */ function validateAlphabetic(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\D/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter an alphabetic value."; } catch(inputError) { window.alert("You can only enter letters into this field."); retValue = false; } finally { return retValue; } } function validateNumeric(keyPressEvent) { if (navigator.appName == "Microsoft Internet Explorer") var enteredKey = keyPressEvent.keyCode; else if (navigator.appName == "Netscape") var enteredKey = keyPressEvent.charCode; var enteredChar = String.fromCharCode(enteredKey); var retValue = true; try { if (!/\d/.test(enteredChar) && !/\W/.test(enteredChar)) throw "You did not enter a numeric value."; } catch(inputError) { window.alert("You can only enter numbers into this field."); retValue = false; } finally { return retValue; } } /* ]]> */ </script> </head> <body> <h1>Challenge Questions</h1> <form action="" enctype="application/x-www-form-urlencoded"> <select> <option value="maiden" onkeypress="return validateAlphabetic(event)">What is your mother's maiden name</option> <option value="pet" onkeypress="return validateAlphabetic(event)">What is the name of your favorite pet?</option> <option value="city" onkeypress="return validateAlphabetic(event)">What city were your born in?</option> <option value="security" onkeypress="return validateNumeric(event)">What is your social security number?</option> <option value="siblings" onkeypress="return validateNumeric(event)">How many siblings do you have?</option> </select><br /> <input type="text" size="25" /> </form> </body> Reply With Quote I'm researching a possible web project. The project will allow users to create and run JS online, similar to JSFiddle, Construct 2 and GameSalad. At this stage I'm just looking to gather general information. So my first question is, just how big of a project would that be? what web technologies would be needed? Would Node.Js be needed? or would PHP be ok for the backend? Thanks for any advice. I am not understanding something here with this: http://www.w3schools.com/jquery/jquery_ajax.asp Code: <html> <head> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").click(function(){ $("div").load('test1.txt'); }); }); </script> </head> <body> <div><h2>Let AJAX change this text</h2></div> <button>Change Content</button> </body> </html> When you click on the button, AJAX changes the text : Code: Let AJAX change this text to: Code: AJAX is not a programming language. It is just a technique for creating better and more interactive web applications. My question is, where is this text above located since it's not in the code? Also, if I wish to change the text mentioned, how can I do so please? Hi All I have a xml string located in a hidden textbox that i need to parse how do i get it into a xml object I thought nievly i could xmlDoc = document.getElementById("XML").value alert(xmlDoc.getElementsByTagName("SupplMets")[0]); document.write("<table border='1'>"); but obviously i need to do some more work to get it into an xml object ...any ideas the end goal here is to get the data in the xml into a table here is what the xml string looks like <SupplMets TumorSupplementalId="272341"><SupplMet TumorSupplMetsId="109130" SiteOfMetastasis="C020" DateOfMetastasis="20010101" MetastasisIdType="" MetastasisEliminated="" MetastasisSD="02-003710" /></SupplMets> I know that global variables are properties of the window object... so does that mean that local variables are properties of the function they belong to? And does that mean that functions are methods of the window object and that nested functions are methods of the function they belong to?
|