|
||
What is JavaScript?A1: JavaScript is a general-purpose programming language designed to let programmers of all skill levels control the behavior of software objects. The language is used most widely today in Web browsers whose software objects tend to represent a variety of HTML elements in a document and the document itself. But the language can be--and is--used with other kinds of objects ...
How is JavaScript different from Java?JavaScript was developed by Brendan Eich of Netscape; Java was developed at Sun Microsystems. While the two languages share some common syntax, they were developed independently of each other and for different audiences. Java is a full-fledged programming language tailored for network computing; it includes hundreds of its own objects, including objects for creating user i...
How do you submit a form using Javascript?refers to the index of the form – if you have more than one form in a page, then the first one has the index 0, second has index 1 and so on).
How do we get JavaScript onto a web page?For example, to add the "last updated line" to your pages, In your page text, add the following: Note: the first comment, "<--" hides the content of the script from browsers that don't understand javascript. The "// -->" finishes the comment. The "//" tells javascript that this is a comment so javascript doesn't try to interpre...
How to detect the operating system on the client machine?JavaScript's greatest potential gift to a Web site is that scripts can make the page more immediately interactive, that is, interactive without having to submit every little thing to the server for a server program to re-render the page and send it back to the client. For example, consider a top-level navigation panel that has, say, six primary image map links into subsect...
How do you convert numbers between different bases in JavaScript?Use the parseInt() function, that takes a string as the first parameter, and the base as a second parameter. So to convert hexadecimal 3F to decimal, use parseInt ("3F", 16);
How to create arrays in JavaScript?Now our array scrips has 4 elements inside it and we can print or access them by using their index number. Note that index number starts from 0. To get the third element of the array we have to use the index number 2 . Here is the way to get the third element of an array.
How do you target a specific frame from a hyperlink?Include the name of the frame in the target attribute of the hyperlink. <a href=”mypage.htm” target=”myframe”>>My Page</a>
What is a fixed-width table and its advantages?Fixed width tables are rendered by the browser based on the widths of the columns in the first row, resulting in a faster display in case of large tables. Use the CSS style table-layout:fixed to specify a fixed width table. If the table is not specified to be of fixed width, the browser has to wait till all data is downloaded and then infer the best width for each of the c...
How to add Buttons in JavaScript?The most basic and ancient use of buttons are the "submit" and "clear", which appear slightly before the Pleistocene period. Notice when the "GO!" button is pressed it submits itself to itself and appends the name in the URL. Another useful approach is to set the "type" to "button" and use the "onclick" event. lt;...
How can JavaScript be used to personalize or tailor a Web site to fit individual users?JavaScript allows a Web page to perform "if-then" kinds of decisions based on browser version, operating system, user input, and, in more recent browsers, details about the screen size in which the browser is running. While a server CGI program can make some of those same kinds of decisions, not everyone has access to or the expertise to create CGI programs. For ...
What is the data type of variables of in JavaScript?GET: Parameters are passed in the querystring. Maximum amount of data that can be sent via the GET method is limited to about 2kb. POST: Parameters are passed in the request body. There is no limit to the amount of data that can be transferred using POST. However, there are limits on the maximum amount of data that can be transferred in one name/value pair. It is true, tex...
What and where are the best JavaScript resources on the Web?The Web has several FAQ areas on JavaScript. The best place to start is something called the meta-FAQ [14-Jan-2001 Editor's Note: I can't point to it anymore, it is broken!], which provides a high-level overview of the JavaScript help available on the Net. As for fact-filled FAQs, I recommend one maintained by Martin Webb and a mini-FAQ that I maintain. For interactive hel...
What are the ways to emit client-side JavaScript from server-side code in ASP.NET?Page.RegisterClientScriptBlock("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>"); Page.RegisterStartupScript("ScriptKey", "<script language=javascript>" + "function TestFn() { alert('Clients-side JavaScript'); }</script>"); Scr...
What is the difference between RegisterClientScriptBlock and RegisterStartupScript?tag. RegisterStartupScript emits the JavaScript at the bottom of the ASP.NET page just before the closing
What is the difference between a web-garden and a web-farm?Web-garden - An IIS6.0 feature where you can configure an application pool as a web-garden and also specify the number of worker processes for that pool. It can help improve performance in some cases. Web-farm - a general term referring to a cluster of physically separate machines, each running a web-server for scalability and performance (contrast this with web-garden whi...
How to set the focus in an element using Javascript?lt;script> function setFocus() { if(focusElement != null) { document.forms[0].elements["myelementname"].focus(); } } </script>
How to access an external javascript file that is stored externally and not embedded?lt;script src="abc.js"></script>How to access an external javascript file that is stored externally and not embedded? where abc.js is the external javscript file to be accessed.
Taking a developer’s perspective, do you think that that JavaScript is easy to learn and use?One of the reasons JavaScript has the word "script" in it is that as a programming language, the vocabulary of the core language is compact compared to full-fledged programming languages. If you already program in Java or C, you actually have to unlearn some concepts that had been beaten into you. For example, JavaScript is a loosely typed language, which means t...
How about 2+5+"8"?Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
What is the difference between SessionState and ViewState?ViewState is specific to a page in a session. Session state refers to user specific data that can be accessed across all pages in the web application.
What does the EnableViewStateMac setting in an aspx page do?Setting EnableViewStateMac=true is a security measure that allows ASP.NET to ensure that the viewstate for a page has not been tampered with. If on Postback, the ASP.NET framework detects that there has been a change in the value of viewstate that was sent to the browser, it raises an error - Validation of viewstate MAC failed. Use <%@ Page EnableViewStateMac="true...
How to Accessing Elements using javascript?To do something interesting with HTML elements, we must first be able to uniquely identify which element we want. In the example lt;input type="button" id="useless" name="mybutton" value="doNothing" />
How to hide javascript code from old browsers that dont run it?Use the below specified style of comments <script language=javascript> <!-- javascript code goes here // --> or Use the <NOSCRIPT>some html code </NOSCRIPT> tags and code the display html statements between these and this will appear on the page if the browser does not support javascript
What is this keyword?Sticky session refers to the feature of many commercial load balancing solutions for web-farms to route the requests for a particular session to the same physical machine that serviced the first request for that session. This is mainly used to ensure that a in-proc session is not lost as a result of requests for a session being routed to different servers. Since requests f...
How to select an element by id and swapping an image ?lt;select name="beer" id="beer" onChange="setButton();setBeerIcon();">
How to find the selected radio button immediately using the 'this' variable?lt;br /><input type="radio" name="marsupial" value="Tasmanian Tiger"
How to find radio button selection when a form is submitted?lt;br /><input type="radio" name="marsupial" value="Opossum" />Opossum lt;br /><input type="radio" name="marsupial" value="Tasmanian Tiger" />Tasmanian Tiger lt;input type="button" name="GO" value="GO" onclick="findButton()" /> Changing the contents of a...
How to create an input box?window.open("http://www.mysite.org/Misc/Pennies", "Pennies", "resizable=yes, status=yes, toolbar=yes, location=yes, menubar=yes, scrollbars=yes, width=800, height=400");
How to setting a cookie with the contents of a textbox ?Values stored in cookies may not have semicolons, commas, or spaces. You should use the handy "escape()" function to encode the values, and "unescape()" to retrieve them.
How to Handle Event Handlers?lt;input type="button" id="hitme" name="hitme" value="hit me" onclick="hitme()" Or, interestingly enough you can just assign the event's name on the object directly with a reference to the method you want to assign. lt;input type="button" id="hitme2" name="hitme2" value="hit me2"/>...
How to change style on an element?Between CSS and javascript is a weird symmetry. CSS style rules are layed on top of the DOM. The CSS property names like "font-weight" are transliterated into "myElement.style.fontWeight". The class of an element can be swapped out. For example: Change the "visibility" attribute of the style object associated with your element. Remember that a...
how to force a page to go to another page using JavaScript?lt;script language="JavaScript" type="text/javascript" ><!-- location.href="http://newhost/newpath/newfile.html"; //--></script>
How to convert a string to a number using JavaScript?You can use the parseInt() and parseFloat() methods. Notice that extra letters following a valid number are ignored, which is kinda wierd but convenient at times.
How tp create Arrays using JavaScript??var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
How to delete an entry using JavaScript?The "delete" operator removes an array element, but oddly does not change the size of the array. var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
How to use strings as array indexes using JavaScript?Javascript does not have a true hashtable object, but through its wierdness, you can use the array as a hashtable. var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
How to use "join()" to create a string from an array using JavaScript?var days = ["Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"];
How to shift and unshift using JavaScript?shift, unshift, push, and pop may be used on the same array. Queues are easily implemented using combinations.
How to create an object using JavaScript?To create an object you write a method with the name of your object and invoke the method with "new". You can also use an abbreviated format for creating fields using a ":" to separate the name of the field from its value. This is equivalent to the above code using "this.".
How to associate functions with objects using JavaScript?Let's now create a custom "toString()" method for our movie object. We can embed the function directly in the object like this. Or we can use a previously defined function and assign it to a variable. Note that the name of the function is not followed by parenthisis, otherwise it would just execute the function and stuff the returned value into the variable. docu...
What's Prototypes for JavaScript?These are similar to the decodeURI() and encodeURI(), but escape() is used for only portions of a URI. document.write("<br />uri part: \"&author="+escape(myvalue)+"\""); Many characters cannot be sent in a URL, but must be converted to their hex encoding. These functions are used to convert an entire URI (a superset of URL) to and fr...
|
|