I have a HTML form that I'd like to POST variables off to another server side script but a javascript function in the form (that I'm using as a graphic on/off button) is acting like a submit button and I've no idea why?
Now this behaviour is somewhat similar to what I actually want to happen but it's unexpected and out my my control, so I just need to know what's going on. Any ideas? Because I thought this situation (a javascript submit button) requires document.myform.submit() and wouldn't happen otherwise.
After the onoff function executes the variables from the form and their values are sent to reminders-update.php
Code:
<form id=\"myform\" method=\"post\" action=\"reminders-update.php\">
<td>
<button class=\"onoff\" onclick=\"onoff(this)\"><div>off</div></button>
</td>
<td>
<input type=\"date\" id=\"freqs\" name=\"date\" />
</td>
<td>
<input type=\"email\" name=\"usremail\" />
</td>
<td>
<td>
<input type=\"submit\" value=\"Send\" />
</td>
</tr>
<script type=\"text/javascript\">
var buttonstate=0;
function onoff(element)
{
buttonstate= 1 - buttonstate;
var blabel, bstyle, bcolor;
if(buttonstate)
{
blabel=\"on\";
bstyle=\"green\";
bcolor=\"lightgreen\";
}
else
{
blabel=\"off\";
bstyle=\"lightgray\";
bcolor=\"gray\";
}
var child=element.firstChild;
child.style.background=bstyle;
child.style.color=bcolor;
child.innerHTML=blabel;
}
</script>