Search

Monday, May 21, 2007

disable button based on text link

Wrote this bit of JavaScript to basically disable the next button unless a link in the content is clicked. It was built to run out of a CMS system so that the JavaScript can go on any page without causing an error, but only disables the next button if the link is contained in the body. It can be used to force users to view links before they can move onto the next page.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Enable me once link is clicked</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

To access the document and enable next button <a href="#" id="fixednext" onClick="javascript:enableMe('next');">click here</a>
<p>
<input name="Next" type="button" id="next" value="Next">
</p>
<p> </p>

<script language="JavaScript">

if (document.getElementById('fixednext')==null) { }
else {
document.getElementById('next').disabled=true;
}

function enableMe(nextid) {
document.getElementById(nextid).disabled=false;
}
</script>

</body>
</html>