Sunday, May 10, 2009

Javascript Saving user name and password to a cookie


<html>
<head>
<script language="JavaScript"><!--
function Get_Cookie(name) {
var start = document.cookie.indexOf(name+"=");
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}a
function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));
function set() {
if (document.logonForm.elements[1].checked)
Set_Cookie("userid",document.logonForm.userid.value,expires);
if (document.logonForm.elements[3].checked)
Set_Cookie("password",document.logonForm.password.value,expires);
}
function get() {
userid = Get_Cookie("userid")
if (userid != null) {
document.logonForm.userid.value = userid;
document.logonForm.elements[1].checked = true;
}
password = Get_Cookie("password")
if (password != null) {
document.logonForm.password.value = password;
document.logonForm.elements[3].checked = true;
}
}
//--></script>
</head>
<body onLoad="get()">
<form name="logonForm" onSubmit="return set();">
<p>Userid: <input type="input" name="userid"> Save <input type="checkbox">
<p>Password: <input type="password" name="password"> Save <input type="checkbox">
<p><input type="reset"> <input type="submit">
</form>
</body>
</html>

Monday, May 4, 2009

Simple Javascript Page Redirect

<script language="javascript">

document.location='YOUR LINK HERE';

</script>

Sunday, April 19, 2009

Javascript Submitting form on pressing the enter key

<html>
<body>
<script language="JavaScript">
function submitonEnter(evt){
var charCode = (evt.which) ? evt.which : event.keyCode
if(charCode == "13"){
document.form1.submit();
}
}
</script>

<form name="form1" action="index.php?mid=72me211v4604" method="POST">
<textarea name="msg" onKeyDown="javascript:return submitonEnter(event);"></textarea>
<br>
<input type="submit" value="Sänd/uppdatera">
</form>
</body>
</html>

Sunday, March 22, 2009

Classic ASP: dump text file contents into array

The code below is reading text file and putting its lines into array.
After the code is executed, each item of the array will be one
line of the text file.


<%

Function ReadTextFile(strFilePath)

 Dim objFSO, objFile, strAllFile

 Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

 Set objFile = objFSO.OpenTextFile(strFilePath)

 strAllFile = ""

 If Not(objFile.AtEndOfStream) Then

  strAllFile = objFile.ReadAll

 End If

 objFile.Close

 Set objFile = Nothing

 Set objFSO = Nothing

 

 strAllFile = Replace(strAllFile, Chr(13)&Chr(10), Chr(13))

 strAllFile = Replace(strAllFile, Chr(10)&Chr(13), Chr(13))

 ReadTextFile = Split(strAllFile, Chr(13))

End Function



'usage

Const FILE_NAME="myfile.txt"

Dim arrLines, x, curLine

Response.Write("reading file: " & FILE_NAME & "...<br />")

arrLines = ReadTextFile(Server.MapPath(FILE_NAME))

Response.Write("amount of lines: " & (UBound(arrLines)+1) & "<br />")

Response.Write("file contents:<hr />")

For x=0 To UBound(arrLines)

 curLine = arrLines(x)

 Response.Write("Line #" & (x+1) & " " & Server.HTMLEncode(curLine) & "<br />")

Next

Response.Write("<hr />")

%>



Source: http://forums.aspfree.com/

Tuesday, March 10, 2009

Loading an XML file with Javascript.

Should fill the data from the XML file into the span tag on the HTML document.

<script type="text/javascript">
function parseXML()
{
try //Internet Explorer
{
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
}
catch(e)
{
try //Firefox, Mozilla, Opera, etc.
{
xmlDoc=document.implementation.createDocument("","",null);
}
catch(e)
{
alert(e.message);
return;
}
}
xmlDoc.async=false;
xmlDocVal = "/xmlfile.xml";
xmlDoc.load(xmlDocVal);
document.getElementById("divtarget").innerHTML=
xmlDoc.getElementsByTagName("xmlnodesource")[0]
.childNodes[0].nodeValue;

XML File
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xmlnodesource>Data</xmlnodesource>

HTML
<span id="divtarget"></span>

Basic ASP XML Output

ASP XML Output

<%
response.contentType="text/xml"
response.write("<?xml version='1.0' encoding='ISO-8859-1'?>")
response.write("<note>mooage</note>")
%>

Tuesday, March 3, 2009

Including a file in ASP

I always forget the exact statement for this for some reason, ill probably remember now ;)

<!--#include file="wisdom.inc"-->

http://www.w3schools.com/asp/asp_incfiles.asp