PDA

View Full Version : combining 2 javascripts



emanuelle
02-19-2009, 01:57 PM
Iwwuld like one checkbox to enable the form and the submit button.
All in one

here is the code:
<head>


<script type="text/javascript">
function toggle() {
var state = !arguments[arguments.length-1];
for(var i=1; i<arguments.length-1; i++) {
document.forms[arguments[0]][arguments[i]].disabled = state;
}
}



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/accept terms to submit form")
return false
}
}
}

</script>
</head>
<body>
<form name="myForm" onSubmit="return defaultagree(this)">
<p>
<input type="checkbox" name="agreecheck" value="oppid" onclick="toggle('myForm', 'fname', 'lname', 'company', 'select', 'textfield', this.checked);">
<br>
<INPUT disabled="true" name="fname" size="30" type="text">
<br>
<INPUT disabled="true" name="lname" size="30" type="text">
<br>
<INPUT disabled="true" name="company" size="30" type="text">
<br>
<select disabled="true" name="select">
</select>
</p>
<p>
<textarea disabled="true" name="textfield" rows="3"></textarea>
</p>
</form>
<br />
<form name="agreeform">
Rest of your form here<br>
<input name="agreecheck" type="checkbox" onClick="agreesubmit(this)"><b>I agree to the above terms</b><br>
<input type="Submit" value="Submit!" disabled>
</form>

<script>
//change two names below to your form's names
document.forms.agreeform.agreecheck.checked=false
</script>

</body>