Forums

Multiple Submit Buttons

cre8tivemedia 20 Jan, 2013
I was wondering how I would go about having more than 1 submit button in a form. In the form, I want to allow a user to input a length and width for a product. I will have the form calculate 3 different prices based on the thickness of the products that I have (1 inch, 2 inch and 3 inch thick). I would like to have a submit button next to each one of these options and based on which one the user clicks on it would run a different part of my custom code in the Load JS part of my "OnLoad" event.

Currently I am using just one submit event. In my general settings of my form under "Form tag attachment" I have

onsubmit= 'calculate()'

. Can I add an additional onsubmit event here just using another name for 'calculate()'? Do I need to name it something other than onsubmit?

Thanks
Matt
cre8tivemedia 22 Jan, 2013
Should I be looking at doing an if else statement somewhere in the onload event?

Maybe like -

if ($_POST['button1'] {
run this code;
} else if ($_POST['button2']) {
run this other code;
}

Little bit lost here :?
GreyHead 22 Jan, 2013
Hi Matt,

If you want to run different parts of your JavaScript then I wouldn't use *submit* buttons at all, use an input of type='button' and use addEvent('click', . . .) to attach JavaScript to it.

Personally I wouldn't put anything in the the Form tag attachment box at all. The addEvent() syntax is much more flexible and keeps the script and HTML separate.

You'll find dozens, if not hundreds of addEvent() examples here and in the FAQs. See the MooTools docs here.

Bob
cre8tivemedia 22 Jan, 2013
Thanks Bob, I had a feeling I was over thinking this....
Matt 8)
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger