41⟩ How to set the focus in an element using Javascript?
Setting the focus in an element using JavaScript
<script>
function setFocus() {
if(focusElement != null)
{
document.forms[0].elements["myelementname"].focus();
}
}
</script>
“JavaScript Tutorial with interview questions and answers. And thousands of JavaScript real Examples.”
Setting the focus in an element using JavaScript
<script>
function setFocus() {
if(focusElement != null)
{
document.forms[0].elements["myelementname"].focus();
}
}
</script>
This can be achieved by using the following tag between head tags or between body tags.
<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 JavaScript file to be accessed.
An alert box displays only one button which is the OK button whereas the Confirm box displays two buttons namely OK and cancel.
A prompt box allows the user to enter input by providing a text box.
Breaking is possible within a string statement by using a backslash at the end but not within any other javascript statement.
that is ,
document.write("Hello world");
is possible but not document.write
("hello world");
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 that a variable doesn't care if it's holding a string, a number, or a reference to an object; the same variable can even change what type of data it holds while a script runs.
The other part of JavaScript implementation in browsers that makes it easier to learn is that most of the objects you script are pre-defined for the author, and they largely represent physical things you can see on a page: a text box, an image, and so on. It's easier to say, "OK, these are the things I'm working with and I'll use scripting to make them do such and such," instead of having to dream up the user interface, conceive of and code objects, and handle the interaction between objects and users. With scripting, you tend to write a _lot_ less code.
The best sites are the ones that use JavaScript so transparently, that I'm not aware that there is any scripting on the page. The worst sites are those that try to impress me with how much scripting is on the page.
Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it’s concatenation, so 78 is the result.
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.
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"%> to set it to true (the default value, if this attribute is not specified is also true) in an aspx page.
JavaScript supports the
for loop, while loop, do-while loop, but there is no foreach loop in JavaScript.
<a href='javascript:window.close()' class='anyCSSClass'> Close </a>
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
Use // for a single line comments in JavaScript and
/* start of Multiple lines comment in JavaScript
Multiple line comments in JavaScript
*/ for block comments in JavaScript
Number.MAX_VALUE
Number.MIN_VALUE
The null value is a unique value representing no value or no object.
It implies no object, or null string, no valid Boolean value, no number and no array object.
Create a new object in JavaScript
var obj = new Object();
//or
var obj = {};
obj["age"] = 17;
//or
obj.age = 17;
Way to append a value to an array in JavaScript
arr[arr.length] = value;
In JavaScript this keywork refers to the current object.