Alert if button pressed

heres my code:

<script language="JavaScript">
var checkobj
function agreesubmit(el){
checkobj=el
if (document.all||document.getElementById){
for (i=0;i<checkobj.form.length;i++){  //hunt down submit button
var tempobj=checkobj.form.elements[i]
if(tempobj.type.toLowerCase()=="submit")
tempobj.disabled=!checkobj.checked
}
}
}

function defaultagree(el){
if (!document.all&&!document.getElementById){
if (window.checkobj&&checkobj.checked)
return true
else{
alert("Please read and accept terms to submit form")
return false
}
}
}
</script>
<script type="text/javascript"><!--
function agreeTerms()
{
document.getElementById("upload").disabled=false
document.getElementById("checkBox").checked=true
}
function denyTerms()
{
document.getElementById("upload").disabled=true
document.getElementById("checkBox").checked=false
}

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src='button_select.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

//--></script>
<input type="checkBox" onclick="if (this.checked) {agreeTerms()} else {denyTerms()}"> <? echo $lang[sinfo];?> <a href="?page=tos"><? echo $lang[tos];?></a>
<input type="submit" value="Upload" class="white" onclick="checksubmit()">

i need to make it like if the button is clicked and there the agreement checkbox is not checked… it should give an alert that the alert is not checked… i know that would require a if and else statement but i cant figure out how to do it

Since this is a JavaScript question and not a PHP question I have moved it to the right forum.

alert() is a JavaScript debugging tool so you shouldn’t be using it in a live web page. In Opera it always contains a checkbox to turn JavaScript off for the entire page and in IE9 the second and subsequent alerts have a checkbox for disabling all future alerts from the page.

You should display any error message either directly in the page itself (using innerHTML is the simplest way to add the text you require and CSS can easily style it so it stands out). If you absolutely must have it appear as a dialog then use a lightbox script to display it.

The other thing to remember is that the JavaScript validation is there only for your visitor’s convenience - you need server side validation to ensure that everyone including those without JavaScript have filled out the form correctly.

Also since no one uses IE4 any more you can get rid of the references to document.all

i realize how to have an alert but my problem is i want an alert if the checkbox is not checked and since my upload button is now an image it looks the same when its disabled so instead i want alert when its disabled

this is what i have tried

<script>
if (
form.checkBox.checked == false
{
alert (‘You didn’t agree to the terms’);
return false;
} else {
return true;
}
}
</script>

<script type="text/javascript">
 if (!form.checkBox.checked)
    {document.getElementById('alert').innerHTML = 'You didn't agree to the terms';}
 return form.checkBox.checked;
 </script>

alert() is a debugging tooloand should NEVER be uploaded to the web. See http://javascriptexample.net/badjs12.php for images of what alerts look like in some modern browsers (where they have options that allow your visitor to bypass what you have put the alert there for in the first place).