Javascript Section Index | Page 5
How can I get all the field names in any given HTML page?
document.myform.length; returns the number of controls on your form.
You can reference them by document.myform.elements(counter);
How can I use client-side JavaScript to check if a browser accepts cookies?
First write a Cookie:
document.cookie = "TestCookie";
Then check for it:
if (document.cookie.indexOf("TestCookie") == -1) alert("Cookies not accepted");
What optional features are available for windows opened with window.open()?
The optional featues that can be used as the 3rd argument in window.open :
Optional features to specify for a new window.
windowFeatures
Description
alwaysLowered(JavaScript 1.2) If yes, creates ...more
Are there any libraries of scripts available for validation of input fields in forms?
Nitesh Naveen points out that Netscape provides just such a library at http://developer.netscape.com/docs/examples/javascript/formval/overview.html. Just include FormChek.js and you'll have suppor...more
How can I display the date and time dynamically within a web page?
Here is the code...
<html> <head> <title>Timer...</title>
<script>
function getDateTime() {
var currDate = new Date();
dateDisplay = (eval(currDate.getMonth())+e...more
I'm trying to access document.referrer and it isn't working. What's up?
I happened to read the following in NetMechanic (found via a google search of the words "document referer"):
Note: the referrer property only works when you use it on a live Web server. If you're ...more
Once I have changed the window status, how do I set it back to normal window functionality?
After setting the window status, you can set the status back by setting status equal to defualtStatus.
<SCRIPT LANGUAGE="JavaScript">
<!-->
top.status="I'm the new Status";
//-->
...more
What is the difference between calling a JavaScript function directly like onClick="a()" and onClick="javascript:a()"?
When a script is expected, there is no difference and you don't need the 'javascript:' there... It is used where the expected input is not a script. For example, in the href of anchor tag if you ...more
How can I use a string as an array index?
When initializing the value, just use the desired index, as in the following:
myarray=new Array();
myarray["blah"]="blah blah blah";
the "blah" indexed element of myarray is equal to "blah blah ...more
How do you change the browser text size (i.e. largest, larger, medium, smaller....) using JavaScript?
For a single document, you will have to use style. e.g. <script>document.body.style.fontSize=12pt;</script>
How can I restrict the user to enter "MM/YYYY" (example 10/1999) format only in a text box.
function checkDateFormat(dateValue)
{
dates = dateValue.split("/");
if(dates.length!=2)
return "1";
if(dates[0].length!=2 || dates[1].length!=4)
return "1";
if(isNan(dates[0]) || ...more
How do I ensure the form contents is validated before submitting it?
Instead of having a submit button, make the button a normal one (give type=button instead of type=submit) and do the validations... and once the validations are complete submit the form explicitly...more
How do you generate a random number from JavaScript?
You can either get the time and manipulate that to give you something random or call Math.random():
<script language="JavaScript"><!--
today = new Date();
num = today.getTime()...more
Where can I find the User's Guide for JavaScript in Internet Explorer?
Microsoft's JScript User's Guide is available at http://msdn.microsoft.com/library/en-us/script56/html/js56jsconjscriptusersguide.asp.more
How can I specify two different link styles in one style sheet? Some links are over a different background color.
In your stylesheet, just use two define two styles.
a.link {
color: Green;
background-color:transparent;
}
a.link:hover {
color: Red;
background-color:transparent;
text-decoration: underline;
}
...more