Satya New Appl Javascript
Satya New Appl Javascript
Satya New Appl Javascript
If you have an HTML form on your web page, many times your visitors may hit the 'Enter' key on their
keyboard, instead of the 'Tab' key, thinking it will advance them to the next form field. However, the 'Enter'
key will actually submit the form. This will cause you to receive incomplete form submissions.
To avoid this problem, you can use a piece of JavaScript within your HTML code that will disable the
'Enter' button within your forms until it is completely filled out.
The above form is real and will subscribe you to our highly popular, free weekly ezine - eTips. However,
this form is also an example of how you can disable the 'Enter' key on your visitors keyboard until your
form is submitted.
Place the following JavaScript code within your web page HTML between your HEAD tags:
function stopRKey(evt)
{
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}
document.onkeypress = stopRKey;
</script>
If you're looking for a way to spice up your web site, this JavaScript tip may be just what you're looking
for. You can use JavaScript to highlight an image when you place your mouse over it.
This JavaScript tip provides a great way to highlight your navigational buttons or whatever you'd like.
Example:
<HTML>
<HEAD>
<SCRIPT language="JavaScript1.2">
function makevisible(cur,which)
{
strength=(which==0)? 1 : 0.2
if (cur.style.MozOpacity)
cur.style.MozOpacity=strength
else if (cur.filters)
cur.filters.alpha.opacity=strength*100
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>
However, this cool little JavaScript code will enable you to display some example default text within a text
box that will disappear when clicked on - much better than your users having to delete the example text.
Example:
Submit
Place your cursor inside the text box to see the text disappear.
Place your form code within your HTML like this:
<FORM action="http://www.domain.com" method="post">
<INPUT type="text" size="25" value="Enter Your Default Text Here" onFocus="if(this.value == 'Enter
Your Default Text Here') {this.value = '';}" onBlur="if (this.value == '') {this.value = 'Enter Your Default
Text Here';}" />
<INPUT type=submit value=Submit>
</FORM>
Change the default text displayed within your text box by editing the code indicated in bold.
major issue. But here, using XML and JavaScript, it's XML that's the
issue: not all browsers support the parsing of XML documents.
I'll use IE6 to explain the codes. Browsers that don't support XML
can't read these, so when you view an XML file in such a browser, it
will simply ignore all the tags.
Sample XML File
Let's consider a sample XML file, which shows employee data and
Turnover of a company:
<?xml version="1.0" ?>
<company>
<employee id="001" sex="M" age="19">Premshree Pillai</employee>
<employee id="002" sex="M" age="24">Kumar Singh</employee>
<employee id="003" sex="M" age="21">Ranjit Kapoor</employee>
<turnover>
<year id="2000">100,000</year>
<year id="2001">140,000</year>
<year id="2002">200,000</year>
</turnover>
</company>
View the entire contents of the XML file using alert(xmlObj.xml); The
whole XML file will be displayed in an alert box as it is, with proper
indentation.
In the above XML file, <company> is the top level tag under which all
other tags fall. These tags are called children. This XML file can be
represented graphically like a folder-tree:
989_folderimage (click to view image)
In the above XML file, the top level tag <company> has 4 children.
You can test whether a particular node child has any children using
childNodes(i).hasChildNodes
In the XML file, the content of the 1st <employee> tag is "Premshree
Pillai". You can get this value using
xmlObj.childNodes(0).firstChild.text
Attributes
In the XML file, the <employee> tag has 3 attributes. An attribute can
be accessed using childNodes(i).getAttribute("AttributeName"). Thus,
xmlObj.childNodes(0).getAttribute("id") will return "001".
xmlObj.childNodes(1).getAttribute("age") will return "24". And
xmlObj.childNodes(2).getAttribute("sex") will return "F".
Go to page: 1 2 Next
• Fundamental Difference is probably the Visibility - GET request is sent via the URL string
(appended to the URI with a question-mark as separator), which is visible whereas POST request is
encapsulated in the body of the HTTP request and can't be seen.
• Length - Since, GET request goes via URL, so it has a limitation for its length. It can't be more than
255 characters long (though this is browser dependent, but usually the max is 255 characters only).
Whereas no such maximum length limitation holds for the POST request for the obvious reason that
it becomes a part of the body of the HTTP request and there is no size limitation for the body of an
HTTP request/response.
• Performance - GET request is comparatively faster as it's relatively simpler to create a GET request
and the time spent in the encapsulation of the POST request in the HTTP body is saved in this case.
In addition, the maximum length restriction facilitates better optimization of GET implementation.
• Type of Data - GET request is sent via URL string and as we all know that URL can be text-only, so
GET can carry only text data whereas POST has no such restriction and it can carry both text as well
as binary data.
• Caching/Bookmarking - again for the obvious reason that a GET request is nothing but an URL hence
it can be cached as well as Bookmarked. No such luxuries with a POST request.
• FORM Default - GET is the default method of the HTML FORM element. To submit a FORM using POST
method, we need to specify the method attribute and give it the value "POST".
• Data Set - GET requests are restricted to use ASCII characters only whereas POST requests can use
the 'enctype' attribute with a value "multipart/form-data" to use the Universal Multiple-Octet Coded
Character Set (UCS).
HTML 4.01 Specification says in the section 17.13.1 Form Submission method:
The "get" method should be used when the form is idempotent (i.e., causes no side-effects). Many database
searches have no visible side-effects and make ideal applications for the "get" method.
If the service associated with the processing of a form causes side effects (for example, if the form
modifies a database or subscription to a service), the "post" method should be used.
I think the above W3C Recommendation makes it pretty clear when to use the GET method and when to use
the POST method.
window.getSelection
Table of contents
1. 1. Summary
2. 2. Syntax
3. 3. Example
4. 4. Notes
5. 5. Specification
6. 6. See also
« Gecko DOM Reference
Summary
Returns a selection object representing the range of text selected by the user.
Syntax
selection = window.getSelection() ;
• selection is a Selection object.
Example
function foo() {
var selObj = window.getSelection();
alert(selObj);
var selRange = selObj.getRangeAt(0);
// do stuff with the range
}
Notes
In JavaScript, when a selection object is passed to a function expecting a string (like window.alert
or document.write ), a string representation of it (i.e. the selected text) is passed instead. This
makes the selection object appear like a string, when it is really an object with its own properties and
methods. Specifically, the return value of calling the toString() method of the Selection object is
passed.
In the above example, selObj is automatically "converted" when passed to window.alert. However, to
use a JavaScript String property or method such as length or substr, you must manually call the
toString method.
Note:
The autocomplete attribute will cost failture of passing W3C validation though this
attribute works in most browsers.
By javascript manual at 7/23/2008 with 0 review(s).
IE version:
document.selection.createRange().duplicate().text;
Firefox version:
document.getSelection();
Unfortunately, this is IE only. For firefox, it raises the error 'setting a property that has
only a getter', beacuase of read-only property of keyCode.
Test:
Forbid to paste:
<input type=text onpaste="return false">
javascript tips 2
Anchor:
<a name="first">
<a href="#first">anchors</a>
Transfer variables:
location.search();
Transparency background:
<IFRAME src="1.htm" width=300 height=180 allowtransparency></iframe>
HTML lable:
document.documentElement.innerHTML
javascript tips 02
Display in one row, Hide element's focus, Wrap line base on width, Auto refresh
webpages, Email link with body and subject filled ... view full content
By javascript manual at 6/30/2008 with 0 review(s).
document.all.css.href = "a.css";
document.all.css.href = "b.css";
document.all.css.href = "c.css";
document.all.css.href = "d.css";
var tb = document.getElementById("tableid");
tb.moveRow(2,1)
By javascript manual at 3/21/2008 with 0 review(s).
obj.parentElement(dhtml)
obj.parentNode(dom)
timer=setInterval('scrollwindow()',delay);
clearInterval(timer);
document.getElementsByName("r1");
document.getElementById(id);
Javascript tips 1
Bind event:
document.captureEvents(Event.KEYDOWN);
Window command:
document.execCommand
Create element:
document.createElement("SPAN");
Get element by mouse:
document.elementFromPoint(event.x,event.y).tagName=="TD
document.elementFromPoint(event.x,event.y).appendChild(ms)
Window images:
document.images[index]
Dropdown:
select.options[index]
select.options.length
event.srcElement.setCapture();
event.srcElement.releaseCapture();
event.srcElement.tagName
event.srcElement.type
This is a reference to the Microsoft XML document object. This object resembles the
W3C DOM core document object in many ways, but Microsoft provide ... view full
content
By javascript manual at 3/14/2008 with 0 review(s).
Contains the URL of the external XML document loaded into the data island. To load a
new document after the fact, assign a new URL to this property. ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
The xml object reflects the Microsoft proprietary xml element, creating a so-called XML
data island inside an HTML document. ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
The content of 'with' chapter is same as javascript Operators with ... view full content
By javascript manual at 7/3/2008 with 0 review(s).
javascript window handleEvent[ ]
Instructs the window object to accept and process the event whose specifications are
passed as the parameter to the method ... view full content
By javascript manual at 7/11/2008 with 0 review(s).
Halts the download of external data of any kind. This method is the same as clicking the
browser's Stop button. ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Lets the browser determine the optimum window size to display the window's content.
Suitable for subwindows that display a limited amount of information. ... view full
content
By javascript manual at 6/28/2008 with 0 review(s).
Displays a special window that remains atop all browser windows, yet allows the user to
interact with other open windows and their content. ... view full content
By javascript manual at 7/17/2008 with 0 review(s).
Displays a special window that remains atop all browser windows until
the user explicitly closes the dialog window. This kind of window is
different ... view full content
By javascript manual at 4/10/2008 with 0 review(s).
Displays a WinHelp window with the .hlp document specified with the URL parameter. ...
view full content
By javascript manual at 3/14/2008 with 0 review(s).
Changes the cursor to a desired type. This method is an alternate to the style sheet
cursor attribute. Starting with Netscape 6.2, a cursor changed ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Scrolls the document in the window to a specific scrolled pixel position. # Horizontal
position in pixels of the window.
# Vertical position in pixels of the window. ... view full content
By javascript manual at 7/12/2008 with 0 review(s).
Scrolls the document in the window by specified pixel amounts along both axes. To
adjust along only one axis, set the other value to zero. Positive ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Sets the scrolled position of the document inside the current window or frame. To return
the document to its unscrolled position, set both parameter ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Used inside an event handler function, this method directs Navigator 4 (only) to let the
event pass to its intended target object. ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
This is a convenience method that shifts the width and height of the window by
specified pixel amounts. To adjust along only one axis, set the other ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
The opposite of window.captureEvents( ) , this method turns off event capture at the
window level for one or more specific events named in the para ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Displays a dialog box with a message, a one-line text entry field, and two clickable
buttons. Script execution halts while the dialog box appears. T ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Starts the printing process for the window or frame. A user must still confirm the print
dialog box to send the document to the printer. This method ... view full content
By javascript manual at 3/14/2008 with 0 review(s).
Opens a new window. You can specify a URL to load into the new window or set that
parameter to an empty string to allow scripts to document.write( ) into that new
window. ... view full content
By javascript manual at 7/15/2008 with 0 review(s).
Window Object
The Window object is the top level object in the JavaScript hierarchy.
The Window object represents a browser window.
A Window object is created automatically with every instance of a <body> or <frameset> tag.
IE: Internet Explorer, F: Firefox, O: Opera.
Document Object
The Document object represents the entire HTML document and can be used to access all elements in a
page.
The Document object is part of the Window object and is accessed through the window.document property.
IE: Internet Explorer, F: Firefox, O: Opera, W3C: World Wide Web Consortium (Internet Standard).