Open main menu
Home
Random
Log in
Settings
About Conservapedia
Disclaimers
Conservapedia
Search
Changes
← Older edit
Newer edit →
JavaScript
(view source)
Revision as of 19:10, August 2, 2010
1,020 bytes added
,
19:10, August 2, 2010
Added example code. Taken from one of my own projects where double-posting was a real problem.
Line 16:
Line 16:
Within class functions, use this to get a public variable, and '''omit''' to get a private variable!
Within class functions, use this to get a public variable, and '''omit''' to get a private variable!
+
== Example Code ==
+
The following example can be used to disable a form button, for example, to prevent double-posting on a forum.
+
<pre>// Following code licensed CC-SA
+
+
function ref(object)
+
{
+
if (document.getElementById) { return document.getElementById(object); }
+
else if (document.all) { return eval('document.all.' + object); }
+
else { return false; }
+
}
+
+
+
function setButton(btnObject)
+
{
+
if ( document.post.btnName && document.post.btnValue )
+
{
+
document.post.btnName.value = btnObject.name;
+
document.post.btnValue.value = btnObject.value;
+
}
+
else if ( document.all.btnName && document.all.btnValue )
+
{
+
document.all.btnName.value = btnObject.name;
+
document.all.btnValue.value = btnObject.value;
+
}
+
+
var postForm = ref('post');
+
postForm.submit();
+
return true;
+
}</pre>
+
To make use of this function, add it to the JavaScript used by your form, and then add the following to the button you wish to disable:
+
<pre>onClick="setButton(this);"</pre>
==Notes==
==Notes==
JlHawkwell
50
edits