Change the value of hidden field and submit on button click

I would like to change the value of issendnow when this button is clicked

<button type="button" class="btn btn-warning" onclick="(makerecurring);">[code]

submitting this form: 

[code]<form class="smart-form" id="group-form" name="group-form" action="#event.buildLink('MassEmail.SendMassMessage')#" method="post"  enctype="multipart/form-data">
<input type="hidden" name="issendnow" id="issendnow" value="1" />

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Hans LangerCommented:
First you need to put the object (or input) into a variable, you can get it using the this:

var myInput= document.getElementById('issendnow')

Open in new window

and them you can modify its properties, like its value, with this:

myInput.value = 2 

Open in new window

so, your button,in one line, will be something like:

<button type="button" class="btn btn-warning" onclick="document.getElementById('issendnow').value = 2">

Open in new window

tryportAuthor Commented:
Thanks for your response. Are you saying put the first two lines within a script tag? Or that I wouldn't even ultimately need the first two lines if I used the button line?
Aurelian ConstantinProgrammer-analystCommented:
As GERENTE said, just replace your (makerecurring); in onClick event of button with document.getElementById('issendnow').value=2; but also add;

So, the working code is (pay attention to the onClick code):

<button type="button" class="btn btn-warning" onclick="document.getElementById('issendnow').value=2;;">

Open in new window

which makes that the value of hidden input issendnow to be changed to 2, and the form to be submitted when you press the button.

I hope it helps.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Hans LangerCommented:
The first 2 lines were only to explain you how it works. If you put it "inline" you do not need to create those 2 lines.
So, in general, if you want  a javascript code be executed you need to put it inside SCRIPT tags or inside an HTML in an event attribute, like "onclick", that will be executed when the user click the object.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tryportAuthor Commented:
Thanks to you both. The problem is it seems to bypass any onsubmit validation I have when it is submitted onclick this way. ?
Hans LangerCommented:
When you use a submit button, when you click on it, it will submit the closest form and trigger the event "onSubmit" of the form. Any other event will not be trigger unless you specify it manually. Like you did on the button event "onClick".
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.