Click to See Complete Forum and Search --> : Form Submit Script


G-Man
02-26-2003, 12:11 PM
I have a form with multiple buttons to submit it. Of course the designer wants these buttons to be images (which don't pass a value like a submit button). So I made this script to submit the form and pass a value to a hidden input (just like the submit button). This functions properly but it sounds like a triple-click when you click one of the buttons. Something's
happening multiple times, I don't know what. Any ideas?

<SCRIPT language="JavaScript1.2">
function submitScript(nextPage) {
if (nextPage == 1) //back
{
document.form2.button_val.value = 1;
}
document.form2.submit();
if (nextPage == 2) //next
{
document.form2.button_val.value = 2;
}
document.form2.submit();
if (nextPage == 3) //done
{
document.form2.button_val.value = 3;
}
document.form2.submit();
if (nextPage == 4) //Florida Private
{
document.form2.button_val.value = 4;
}
document.form2.submit();
if (nextPage == 5) //Florida Public
{
document.form2.button_val.value = 5;
}
document.form2.submit();
if (nextPage == 6) //Fortune 500
{
document.form2.button_val.value = 6;
}
document.form2.submit();
if (nextPage == 7) //International
{
document.form2.button_val.value = 7;
}
document.form2.submit();
if (nextPage == 8) //Government
{
document.form2.button_val.value = 8;
}
document.form2.submit();
}
</SCRIPT>

Charles
02-26-2003, 12:21 PM
If you use <input type="image" src="http://www.w3.org/Icons/w3c_home" alt="W3C" name="W3C"> then you will end up with a submit button that will also give you the name of the button. Or you could use a separate form for each button.

Keep in mind that JavaScript will fail at least one in ten times and that relying upon it may violate accessibility laws. It certainly violates accessibility guidelines.

G-Man
02-26-2003, 12:47 PM
Charles,
I've tried using the input type="image" name="next_button" value="next_button" src="..." and when the form is posted I don't get a form.next_button value. There is a next_button.x and next_button.y value? I may have to work with these, but I have no idea where the x and y come in.

Charles
02-26-2003, 01:10 PM
Those are pixel coordinates on the image like with a server side image map. See http://www.w3.org/TR/html4/interact/forms.html#h-17.4.1.