I am working on a web project using structs2. I have a form with submit button and another button. I am using javascript functions for form validation. My problem is that when I click the other button the form validation function works.
my jsp:
<h2>New Form</h2>
<s:form action="aa.action" name="myform" method="post" onsubmit="return(validateForm())">
<s:textfield name="formnumber" size="20" />
.
.
<button value="add" name="add">Add</button>
.
.
<s:submit method="create" key="xxx" value="xxx" />
When i click anyone of the the button the validation function will excecute.I dont want excecute the validation function on add button click.
Default button always submit the form so add type="button" it will stop
<button type="button" value="add" name="add">Add</button>
OR Use
<input type="button" name="add" value="Add" />
Get rid of the onclick. You don't need it here. The type="add" already submits the form. Your concrete problem is likely caused because the onclick of the <form> has returned false.
<input type="button" name="method" value="Add" class="button"
onclick="location.href='Employeelist.jsp'" />
You should mention type="button".
Otherwise it will submit the current URL again.
<button type="button" value="Add" name="add"/>
details about "type" in html
http://www.w3schools.com/tags/att_button_type.asp
Java Script Form validation can be
w3schools
Tutorials point
javaScript Coder
if you familier with java script libraries you can use validate.js
type : What type of widget you want.
vlaue : The text what you want in that.
name : The id of that purticulat widget.
Related
I have two different buttons like this :
<input type="button" name="but1" id="but1" value="page1" onclick="f('WebForm1')" />
<input type="button" name="but2" id="but2" value="page2" onclick="f('WebForm2')" />
and obviously two other webforms ("WebForm1" and "WebForm2").
using JavaScript, how can I submit the information from the default webform (which I have the buttons in it) to the page that is the value of its button?
(I mean when I click the first button, it should go to WebForm1 and submit data and when I click the second button, it should go to WebForm2 and submit the data)
I've never tried this before so in JavaScript I wrote
function f(t){
var a;
a = document.getElementById['form1'];
a.submit(t); }
but its not working.
Are all these functionalities to be implemented on the same page?
How I see it, you can make the two input buttons the submit buttons of the two different forms.
<form action = "WebForm1">
<input type= submit name="but1" id="but1" value="page1" />
</form>
<form action = "WebForm2">
<input type= submit name="but2" id="but2" value="page2" />
</form>
Also, I'm not sure if anything like a.submit(t) even works.
In HTML5 you can use <button> with form attribute:
<button type="submit" form="form1" value="Submit">Submit</button>
with form attribute you can specify the form element the <button> element belongs to.
Then, in your form:
<form action="WebForm1" method="get" id="form1">
...
</form>
hope this will help. t is the name of the form.
function f(t){
// <form name="WebForm1">
// t is the name of the form
document.t.submit();
}
this work only if the two form are in the same page as where the button are.
I have used jquery wizard plugin to create this form.
The form get submitted when I use the ID = "next" submit button.
when I use the ID = "quick" button it will redirect to the Feedback.Form but it will not submitted properly. (I cant see the db has been updated properly.)
$j("#quick").click(function(){
$j('#feedbackForm').submit();
});
<form id="feedbackForm" method="post" action="<openmrs:contextPath/>/module/feedback/addFeedback.form" class="bbq" enctype="multipart/form-data" >
<div id="bottomNavigation">
<input id="back" value="Back" type="reset" />
<input id="next" value="Next" type="submit" />
<input id="quick" value="Just submit now with all the defaults!" type="button" />
</div>
Please can any one help me on this?
Thanks,
Harsha
Full source : https://gist.github.com/3227043
Convert the "next" button to normal button and add and if or switch selection into the jquery code. So both buttons were normal and Jquery will decide which ones takes to submit getting the name of the button who calls the click event. Or you can do it trough a javascript function, well, you can do it in any way as you want, but both buttons must be "button" type
i am trying to create a link that submits a form. I use this and works fine :
<a name="submit" href="javascript:document.theForm.submit();" class="rollover-button gray small"><span>Send Message</span></a>
However, i have a problem. My previous submit button was :
<input type="submit" name="submit" value="Send Message" />
When this was clicked, i was getting a $_POST['submit'] value that i was checking with isset in my php script, to see whether the form is submitted or not. However, this does not work with my submit link. Does anybody know how i can do that ?
EDIT:
I tried that, as suggested :
<form action="." name="theForm" class="contactForm" method="post">
<input type="hidden" name="submit" value="Send Message" />
</form>
<a name="submit" href="javascript:document.theForm.submit();" class="rollover-button gray small"><span>Send Message</span></a>
But still does not work.
You can create input type of hidden and check for its existence:
if (isset($_POST['hiddenName'])) {....}
You can use a hidden field instead. So when the form is submitted, you can check if the hidden element exists.
Like this:
<input type="hidden" name="submit" value="Send Message" />
This way, you can check for $_POST['submit'] when you submit the form. Just make sure the hidden <input> is inside the <form> element, so it will POST with the rest of the form.
add a hidden input.
<input type="hidden" name="submit" value="Send Message" />
it will not be visible to the user, but it will be send with the form contents.
You can always hide the submit button (with css display: none) and click it with JavaScript:
document.forms.theForm.elements.submit.click();
I have following code in my popup jsp:
<input type="submit" value="Mod" onclick="remind()" ></input>
<input type="hidden" value="Mod" name="db_remind" id ="remindbutton"></input>
<%--
<input type="submit" value="Delete" onclick="confirmDelete()" > </input>
<input type="hidden" value="Delete" name="db_delete" id="deletebutton" > </input>
Hidden button calls for a Spring controller method. Script is needed to close the popupwindow right after the method is committed.
Each script is like:
function save() {
$('#savebutton').click();
window.close();
}
My problem is that my solution works only, if only one of the jsp function calls is present, in each case. You might say that my solution to achieve what i want is a bit silly, but im a newbie with this and i wonder why all the function calls cannot work together?
Please edit the question to make your issue more clearer. From what I can see you are trying to call different java script functions on click of different buttons.
Do not use input type = "submit" for the buttons. Use input type = "button"
<input type="button" value="remindId" onclick="remind()" ></input>
<input type="button" value="saveId" onclick="save()"></input>
And in javascipt tag:
<script>
function remind()
{ /* Do form submit here */}
function save()
{ /* Do form submit here */}
</script>
I have inherited a project and there is a form with 3 buttons:
<input type="submit" id="ctl00_contentPlaceHolder_back" value="Make Changes" name="ctl00$contentPlaceHolder$back" onClick="history.back();">
<input type="submit" id="ctl00_contentPlaceHolder_preview" value="View Outside" name="ctl00$contentPlaceHolder$preview">
<input type="submit" id="ctl00_contentPlaceHolder_submit" value="Send Card" name="ctl00$contentPlaceHolder$submit">
How do I make it so, that only 1 button actually submits the form to another page for processing?
Change all the other ones to type="button"
Change the input type="button" instead of type="submit". These kind of look like ASP controls, so find and replace these form buttons with a plain button, unbound.
By not letting them be submit buttons. Use type="button" instead of type="submit".