This question already has answers here:
Submit two forms with one button
(7 answers)
Closed 8 years ago.
I have two different forms. Each of them has its own submit button
<input type="submit" id="edit-submit" name="op" value="Submit" class="form-submit ajax-processed">
and
<input type="submit" id="edit-submit--2" name="op" value="Submit" class="form-submit ajax-processed">
I need to make a separate button that would click on these two input. How can I do this?
If you have more than 2 forms and only want 2 of them to be submited, they must have a common part, like a css class (no styling here, only a selector).
HTML part :
<form id="form1" class="myForm ..."/>
<form id="form2" class="myForm ..."/>
<input type="button" id="myButton" value="Submit both forms"/>
js :
$("#myButton").click(function(){
$(".myForm").submit();
});
You can add as many form as you want, if they have the class myForm, they will be submited too. No need to change your js code...
Just provides the ids to your form.for example:
<form id="form1" class="myForm ..."/>
<form id="form2" class="myForm ..."/>
<input type="button" value="Click Me!" onclick="submitForms()" />
<script>
submitForms = function(){
document.getElementById("form1").submit();
document.getElementById("form2").submit();
}
</script>
Related
This question already has answers here:
Auto submit form on page load
(5 answers)
Closed 4 years ago.
hey can anyone help me
I would like to automatically submit the form on page load is there anyway it could be done?
<form method='post' action='/delete-account.php'>
<input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>
<form method='post' name="myForm" id="myForm" action='/delete-account.php'>
<input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>
window.onload=function(){
document.forms["myForm"].submit();
}
You can submit this way by using the jquery
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
document.getElementById("myDataForm").submit();
});
</script>
</head>
<body>
<form method='post' id="myDataForm" name="myDataForm" action='/delete-account.php'>
<input type="submit" id="submit" name="submit" value="Confirm Account Removal" /></form>
</body>
</html>
Please try this.
This question already has answers here:
"Submit is not a function" error in JavaScript
(19 answers)
Closed 5 years ago.
<form name="formName" id="formName" action="" method="post" autocomplete="off">
<input type="hidden" name="text1" id="text1" value='0' />
<input type="button" name ="submit" onClick="Submit()" value="submit">
</form>`
<script>
function Submit() //my function
{
document.getElementById("formName").submit();
}
</script>
I need some help... I have also tried `this document.formName.submit();` but still not working.
on debugging i got this error :Uncaught ReferenceError: formNameis not defined
JavaScript code goes into a <script> tag, otherwise it is just rendered as text and is not interpreted as code.
<form name="formName" id="formName" action="" method="post" autocomplete="off">
<input type="hidden" name="text1" id="text1" value='0' />
<input type="button" name ="submit" onClick="Submit()" value="submit">
</form>`
<script>
function Submit() //my function
{
document.getElementById("formName").submit();
}
</script>
JavaScript is also case sensitive so "Submit" is not the same as "submit".
And you should never name a form input "submit", read: "Submit is not a function" error in JavaScript.
Your javascript code isn’t in tag. What you are going to do is taging and put your code between tags.
<script>
Put Your codes here
</script>
And change submit() to Submit() in onClick
I am attempting to create an order form. I want it so that when you select the button to print out your order to also have it reset all the selected buttons. For the sake of simplicity I have given an extremely simplified version of my actual order form:
Html:
<form id="myForm">
<input type="checkbox">
<input type="button">
<input type="button" onclick="reset();"
</form>
Javascript:
function reset(){
document.getElementById("myForm").reset();
}
My Problem is that when I click the button to reset the page, the checkboxes stay selected.
If you want to just reset the for then use RESET button as bellow
<form id="myForm">
//YOUR FORM ELEMENT EITHER CHECKBOX OR OTHERS
<input type="reset" value='RESET'/>
</form>
Now there is no need to write any script code, type='reset' will automatic handle reset of all element inside your form tag.
There is an unbalanced tag in your html, also input type='reset' can be used to reset the form
function reset() {
document.getElementById("myForm").reset();
}
<form id="myForm">
<input type="checkbox">
<input type="button">
<input type="button" onclick="reset()" value="button reset">
<!--Adding new input type -->
<input type="reset" value="reset"> </form>
</form>
Problem is your HTML, the last input button is not closed properly
Here is working JSfiddle
<form id="myForm">
<input type="checkbox">
<input type="button">
<input type="button" onclick="reset();">
</form>
Javascript code
function reset(){
document.getElementById("myForm").reset();
}
This question already has an answer here:
JavaScript form submit WITH a field called submit
(1 answer)
Closed 6 years ago.
How to submit form when have input type="submit" inner form using javascript ?
i want to submit form using javascript (have input type="submit" inner form ).
i tried to use this code
<form action="" method="post" name="test_fn">
<input type="text" name="input1" value="ON">
<input type="submit" name="submit" value="ON">
</form>
<script type="text/javascript">
setTimeout(function(){test_fn.submit();}, 0);
</script>
but not work. how can i do that ? for submit form using javascript (have input type="submit" inner form )
thank
First you should change your input submit name.
When you name the button submit, you override the submit() function on the form,so it will become "submit is not a function"
<form action="" method="post" name="test_fn" id="test_fn">
<input type="text" name="input1" value="ON">
<input type="submit" name="btnsubmit" value="ON"> //Changed submit name here
</form>
then can call submit by your form name like this
<script type="text/javascript">
setTimeout(function(){document.test_fn.submit()}, 0);
</script>
I'm working on a project for school and I'm stuck on how to reset all the textboxs on the page. This is what my reset button looks like:
<form name="Reset">
<input type="button" value="New ordering sheet." onClick="Reset()">
</form>
I don't know what to do for the function, I have no code for the Reset() function:
function Reset() {}
Have a look at the following questions, there are a few ways of doing it in them:
How to clear all textboxs in a DIV using jQuery?
JQuery how to clear all the input:textfields of a .class on a form. Not working for me
i think this can help!! just have a 'reset' input inside your form :-)
<form name="myform" action="http://something" method="POST">
<input type="text" size="25" value="Enter your name here!">
<input type="submit" value="Send me your name!">
<input type="reset" value="Reset!">
</form>