Agree Before Posting
JavaScriptSource Staff Nov 16, 2007
General
Sometimes you may need to make sure your visitors agree to specific terms before submitting their comments. This script will disable the input fields until they agree to your terms. Easily adaptable.
Source Code
Paste this source code into the designated areas.
External file
Paste this code into an external JavaScript file named: agreeBeforePosting.js
Select code
/* This script and many more are available free online at
The JavaScript Source!! http://www.javascriptsource.com
Created by: Savvy | http://www.webdeveloper.com/forum/showthread.php?p=819275#post819275 */
function enableob(o) { eval(o+".disabled = false"); }
function disableob(o) { eval(o+".disabled = true"); }
function toggleform(formstr,chkobstr,obstr) {
var checked = eval(formstr+"."+chkobstr+".checked");
var obs = obstr.split(",");
for (i = 0; i < obs.length; i++) {
obs[i] = formstr+"."+obs[i];
}
if (checked == false) {
for (i = 0; i < obs.length; i++) {
disableob(obs[i]);
}
}
else {
for (i = 0; i < obs.length; i++) {
enableob(obs[i]);
}
document.getElementById('pname').focus();
}
}
Head
Paste this code into the HEAD section of your HTML document.
Select code
<script type="text/javascript" src="agreeBeforePosting.js"></script>
Body
Paste this code into the BODY section of your HTML document
Select code
<form name="myform">
<p>To accept the license terms for posting, click the checkbox below:<br>
<input type="checkbox" name="mycheck" onclick="toggleform('document.myform','mycheck','pname,pemail,ptext')"> I Accept</p>
<table>
<tr>
<td><b>Name:</b></td><td><input type="textbox" id="pname" name="pname" disabled="true"></td>
</tr><tr>
<td><b>E-Mail:</b></td><td><input type="textbox" name="pemail" disabled="true"></td>
</tr><tr>
<td><b>Post:</b></td><td><textarea name="ptext" disabled="true"></textarea></td>
</tr>
</table>
</form>
Leave a Response
(1 comment)halllo