Click to See Complete Forum and Search --> : submit form automatically onChange of form


loonaticmedia
05-09-2003, 10:59 AM
hi,

i've got a problem.

i would like to submit a form on change of a form without clicking a button:

that's what i have so far:

---
<script>
var iscomplete=false
function checkform() {
iscomplete=true
for (i=0;i<=document.myform.elements.length-1;i++) {
if (document.myform.barcode.value=="") {iscomplete=false}
}
if (!iscomplete) {
window.status="Bitte Feld ausfüllen!"
if (document.all) {
submitbutton.style.visibility="HIDDEN"
iscomplete=false
}
if (document.layers) {
document.myform.submitbut.value="NOT YET"
iscomplete=false
}
}
if (iscomplete) {
window.status="Super, jetzt kanns losgehen!"
if (document.all) {
submitbutton.style.visibility="VISIBLE"
iscomplete=true
}
if (document.layers) {
document.myform.submitbut.value="NOW"
iscomplete=true
}
}

var timer= setTimeout("checkform()",4000)
}

function oksubmit() {
return iscomplete
}
</script>
<body bgcolor="#FFFFFF" onLoad="checkform(), document.myform.barcode.focus()">
<form NAME="myform" onSubmit="return oksubmit()" ACTION="mailto:isnotareal@emailadress.org" METHOD="POST">
<center>
<table BORDER="0" CELLSPACING="0"
CELLPADDING="1">
<tr valign="top">
<td bgcolor="CCCCCC">&nbsp;<font SIZE="1" face="Verdana">Barcode:</font></td>
<td bgcolor="CCCCCC" align="right"><input NAME="barcode" TYPE="Text" id="barcode" SIZE="30" MAXLENGTH="50">
&nbsp;</td>
</tr>
</table>
</center>
<div align="center" id="submitbutton" style="visibility:hidden">
<center>
<table BORDER="0" CELLSPACING="0" CELLPADDING="0">
<tr valign="top">
<td align=middle><input type="submit" name="Submit" value="Abschicken">
</td>
</tr>
<tr>
</table>
</center>
</div>
</form>

please help me, i can't get it work

best regards
chris

Charles
05-09-2003, 12:52 PM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<form action="" name="king" onsubmit="validate(this)">
<div>
<input type="text" name="tut">
</div>
<script type="text/javascript">
<!--
function validate(f) {return confirm('Submit?')}
document.forms.king.tut.onchange = function () {if (validate(document.forms.king)) document.forms.king.submit()};
// -->
</script>

<noscript><div><input type="submit"></div></noscript>
</form>

Just two things of which you must beware ... Not everybody has JavaScript so you will need to use the NOSCRIPT element to provide a submit button for those folks who don't. And form.submit() will not call the onsubmit handler so you have to call it explicitly.