Submit form automatically [duplicate] - javascript

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.

Related

How to call the form button sitting in div?

Below are my codes for form:
<form accept-charset="utf-8" action="https:example.com" method="get" name="test">
<div class="classy"><input type="button" class="buttonE buttonC" value="CLICK NOW"/></div>
</form>
I have the script below to call the button to submit, it's failed, but if I remove the div class, it can run successfully.
<script>
$('.buttonE').click(function(e){
$(this).parent().trigger('submit')
})
</script>
Could you help to provide me with the proper script to call the button which sitting in div class? Thanks in advance!
This is the most simple solution I can think of.
To simply remove the click handler for the button and set it as the type="submit" for the form.
<form accept-charset="utf-8" action="https:example.com" method="get" name="test">
<div class="classy">
<input type="submit" class="buttonE buttonC" value="CLICK NOW"/>
</div>
</form>
If you really want to use the code like you have it, then you need to use parent twice, because parent of .buttonE is <div class="classy">
<script>
$('.buttonE').click(function(e){
$(this).parent().parent().trigger('submit');
});
</script>
you can set a class for form like this:
$('.buttonE').click(function(e){
$(".form-app").trigger('submit')
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form accept-charset="utf-8" action="https:example.com" method="get" name="test" class="form-app">
<div class="classy">
<input type="button" class="buttonE buttonC" value="CLICK NOW"/> </div>
</form>
notice: If you have already imported the JQuery library, you do not need this code line here:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

document.getElementById("myForm").submit() is not working [duplicate]

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

How to submit form when have input type="submit" inner form using javascript? [duplicate]

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>

How create a button click on intut [duplicate]

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>

submit form with <button type="submit"> to the same page

I have the following form:
<form method="post" action="" enctype="multipart/form-data">
<input type="text" name="name_car" />
<input type="submit" name="submit" class="btn" value="Add car" />
</form>
then to fetch the field use:
if($_POST['submit'])
{
$name_car= $_POST['name_car'];
....
}
So far so good. Now do the same with a button. Something of this kind (in the code below) and that the process to fetch the data is equal.
<form method="post" action="" enctype="multipart/form-data">
<input type="text" name="name_car" />
<button class="btn" type="submit" name="wizard-submit"></button>
</form>
The condition you are testing for to see if the form has been submitted is no longer true.
Original HTML:
name="submit"
New HTML:
name="wizard-submit"
The test in PHP:
if($_POST['submit'])
Additionally, your button has no value attribute, you'll need to add one (since otherwise $_POST['submit'] still isn't true)
You should also add some content to the button so that people know what it does.
<button class="btn" type="submit" name="submit" value="something">Submit</button>
If you want to use a button instead of input type submit replace $_POST["submit"] with your button name $_POST["wizard-submit"].
Then if you want your form be single page, change the form file extension to php and include your form process code in it.
NOTICE: use isset instead of vanilla if condition:
if ($_POST["submit"])
replace with:
if (isset($_POST["submit"]))
You can do that. Just put the path to the form in 'action' field.
did you try with the
if (isset ($_POST['submit']))
now the if condition only will be true if there are data, if it's null will be false.
The page with the form has to be saved as a PHP- document with the following code:
<form action="" method="post" enctype="multipart/form-data">
<input type="text" name="new_car" id="new_car" />
<input type="submit" name="submit" class="btn" value="new_car" />
</form>
if($_POST['submit']){
$var=$_POST['submit'];
}

Categories

Resources