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

tryportAsked:
Who is Participating?
 
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.
0
 
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

0
 
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Aurelian ConstantinProgrammer-analystCommented:
As GERENTE said, just replace your (makerecurring); in onClick event of button with document.getElementById('issendnow').value=2; but also add document.group-form.submit();

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

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

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.
0
 
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. ?
0
 
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".
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.