PDA

View Full Version : A few JavaScripts for you!



dani342us
12-06-2005, 08:35 PM
Hey I have decided to make a tutoral or tips for all the people who need some help for their websites.So I am making a post saying some of the Scripts I know and use.So I really hope it helps all of you.Also,I hope it gets stickied...Here are the codes.Were ever you see "Change Me" you may put waht ever you want in it.This is my first tutoral.

Close window button-
Simply put this below the <head> section of your page.

<form>
<input type="button" value="Close Window" onClick="window.close()">
</form>

<a href="javascript:window.close()">Change Me</a>


Slowly come together...status bar-
Put this in <body>

<SCRIPT LANGUAGE="JavaScript">


// set speed of banner (pause in milliseconds between addition of new character)
var speed = 10

// decrease value to increase speed (must be positive)
// set pause between completion of message and beginning of following message
var pause = 1500

// increase value to increase pause
// set initial values
var timerID = null
var bannerRunning = false

// create array
var ar = new Array()

// assign the strings to the array's elements
ar[0] = "Change Me"
ar[1] = "Change Me"
ar[2] = "Change Me"
ar[3] = "Change me"

// assign index of current message
var message = 0

// empty string initialization
var state = ""

// no value is currently being displayed
clearState()

// stop the banner if it is currently running
function stopBanner() {
// if banner is currently running
if (bannerRunning)
// stop the banner
clearTimeout(timerID)
// timer is now stopped
timerRunning = false
}

// start the banner
function startBanner() {
// make sure the banner is stopped
stopBanner()
// start the banner from the current position
showBanner()
}

// assign state a string of "0" characters of the length of the current message
function clearState() {
// initialize to empty string
state = ""
// create string of same length containing 0 digits
for (var i = 0; i < ar[message].length; ++i) {
state += "0"
}
}

// display the current message
function showBanner() {
// if the current message is done
if (getString()) {
// increment message
message++
// if new message is out of range wrap around to first message
if (ar.length <= message)
message = 0
// new message is first displayed as empty string
clearState()
// display next character after pause milliseconds
timerID = setTimeout("showBanner()", pause)
}
else {
// initialize to empty string
var str = ""
// built string to be displayed (only character selected thus far are displayed)
for (var j = 0; j < state.length; ++j) {
str += (state.charAt(j) == "1") ? ar[message].charAt(j) : " "
}
// partial string is placed in status bar
window.status = str
// add another character after speed milliseconds
timerID = setTimeout("showBanner()", speed)
}
}

function getString() {
// set variable to true (it will stay true unless proven otherwise)
var full = true
// set variable to false if a free space is found in string (a not-displayed char)
for (var j = 0; j < state.length; ++j) {
// if character at index j of current message has not been placed in displayed string
if (state.charAt(j) == 0)
full = false
}
// return true immediately if no space found (avoid infinitive loop later)
if (full) return true
// search for random until free space found (braoken up via break statement)
while (1) {
// a random number (between 0 and state.length - 1 == message.length - 1)
var num = getRandom(ar[message].length)
// if free space found break infinitive loop
if (state.charAt(num) == "0")
break
}
// replace the 0 character with 1 character at place found
state = state.substring(0, num) + "1" + state.substring(num + 1, state.length)
// return false because the string was not full (free space was found)
return false
}

function getRandom(max) {
// create instance of current date
var now = new Date()
// create a random number (good generator)
var num = now.getTime() * now.getSeconds() * Math.random()
// cut random number to value between 0 and max - 1, inclusive
return num % max
}
startBanner()
// -->
</SCRIPT>

Auto Refresh-
put this in below <head>

<script>
<!--



//enter refresh time in "minutes:seconds" Minutes should range from 0 to inifinity. Seconds should range from 0 to 59
var limit="Time Here"

if (document.images){
var parselimit=limit.split(":")
parselimit=parselimit[0]*60+parselimit[1]*1
}
function beginrefresh(){
if (!document.images)
return
if (parselimit==1)
window.location.reload()
else{
parselimit-=1
curmin=Math.floor(parselimit/60)
cursec=parselimit%60
if (curmin!=0)
Minutes" minutes and "Seconds Here" seconds left until page refresh!"
else
curtime=cursec+" seconds left until page refresh!"
window.status=curtime
setTimeout("beginrefresh()",1000)
}
}

window.onload=beginrefresh
//-->
</script>

Random Picture-
Under <body>

<script language="JavaScript">
<!--



function random_imglink(){
var myimages=new Array()
//specify random images below. You can have as many as you wish
myimages[1]="image1.gif"
myimages[2]="image2.gif"
myimages[3]="image3.gif"
myimages[4]="image4.gif"
myimages[5]="image5.gif"
myimages[6]="image6.gif"

var ry=Math.floor(Math.random()*myimages.length)
if (ry==0)
ry=1
document.write('<img src="'+myimages[ry]+'" border=0>')
}
random_imglink()
//-->
</script>

<p align="center"><font face="arial" size="-2">This free script provided by</font><br>
<font face="arial, helvetica" size="-2"><a href="http://javascriptkit.com">JavaScript
Kit</a></font></p>

Login and Password protected-
Under <body>

<script language="javascript">
<!--//
/*This Script allows people to enter by using a form that asks for a
UserID and Password*/
function pasuser(form) {
if (form.id.value=="JavaScript") {
if (form.pass.value=="Kit") {
location="What site?"
} else {
alert("Invalid Password")
}
} else { alert("Invalid UserID")
}
}
//-->
</script>

<center>
<table bgcolor="white" cellpadding="12" border="1">
<tr><td colspan="2"><center><h1><i><b>Login
Area</b></i></h1></center></td></tr>
<tr><td><h1><i><b>UserID:</b></i></h1></td><td><form name="Change Me"><input
name="id" type="text"></td></tr>
<tr><td><h1><i><b>Password:</b></i></h1></td><td><input name="pass"
type="Change Me"></td></tr>
<tr><td><center><input type="button" value="Login"
onClick="pasuser(this.form)"></center></td><td><center><br><input
type="Reset"></form></td></tr></table></center>

Random PassWord-
Under <body>

<script>



var keylist="abcdefghijklmnopqrstuvwxyz123456789"
var temp=''

function generatepass(plength){
temp=''
for (i=0;i<plength;i++)
temp+=keylist.charAt(Math.floor(Math.random()*keyl ist.length))
return temp
}

function populateform(enterlength){
document.pgenerate.output.value=generatepass(enter length)
}
</script>

<form name="pgenerate">
<input type="text" size=18 name="output">
<input type="button" value="Generate Password" onClick="populateform(this.form.thelength.value)"><br>
<b>Password Length:</b> <input type="text" name="thelength" size=3 value="7">
</form>

I really hope this works and helps all of you guys that need help.Thank You.

RLY-CRAIG?
13-06-2005, 08:50 AM
Thanks Dani-These heped me! :)

JoeComins
14-06-2005, 07:35 PM
it seems that you have only copied these off a site and added the quote codes. This is not really makeing a tutorial as it isn't your work

dani342us
15-06-2005, 12:02 AM
You dont haveto to make your own script or stuff to make a tutoral,yes I did get if off a site but it is just to help people who need some help with theyr websites.

Want to hide these adverts? Register an account for free!