Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

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>

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>

Thursday, February 26, 2009

Javascript - Selecting a text box on page Load

If you want to have a text input box on your page highlighted on first load, you can use the following java script.

insert into the section of your HTML document:

<script language="javascript" type="text/javascript">
function selectThis() {
var selectval = document.getElementById("textboxid");
selectval.select(); }
</script>

insert into the head tag:
<body onload="selectThis();">

This will select a text box on page load, eg.:
<input type="text" id="textboxid" value="foo">

Also if you would like to have the text highligted as soon as the box is clicked, you can use the tag:
onclick:this.select();

full link:
<input type="text" id="textboxid" value="foo" onclick="this.select();">