onsubmit and confirm always processing form? [duplicate] - javascript

This question already has answers here:
JavaScript Form Submit - Confirm or Cancel Submission Dialog Box
(6 answers)
Closed 7 years ago.
Sorry if its question is reasked. I'm creating a form and asking user to confirm but its not working its always proceding whether user clicks ok, cancel or even close the confirm window. Here is the code:
FORM:
<form action="simple_things.php" class="right inline" method="POST" onsubmit="confirm_input();">
<input type="submit" class="btn red small" name="reset" value="Reset Points">
<input type="submit" class="btn red small" name="reset" value="Reset Referals">
</form>
Script
<script type="text/javascript">
function confirm_input() {
var r = confirm("Do you really wanted to reset?");
return r;
} </script>

Check out this and let me know if you are facing any error.
<form action="simple_things.php" class="right inline" method="POST" onSubmit="return confirm('confirm ?');">
<input type="submit" class="btn red small" name="reset" value="Reset Points">
<input type="submit" class="btn red small" name="reset" value="Reset Referals">
</form>

Thats because the type of both the buttons are submit. Use type submit only on the button that you want to confirm the submission.

Related

button restriction alerts popover titles

I have the following scenario with the form bellow:
<form action="action.php">
<input type="text" id="input1" name="input2">
<input type="text" id="input2" name="input2">
<button type="button" class="btn btn-lg btn-danger" data-toggle="popover" title="Popover
title" data-content="You don't have permission to press button">Button</button>
</form>
I need some Javascript code that says:
if input1=input2 submit form else popover title saying "You don't have permission ". I tried some stuff based on some search on the internet but it didn't really work

Tricky form submission [duplicate]

This question already has answers here:
Bypass HTML "required" attribute when submitting [duplicate]
(4 answers)
Closed 2 years ago.
how can you submit a form by bypassing the required attribute using button 2
like i have button 2 and button 1
i want to submit form by clicking button 2 and bypass required attribute
and both buttons must have type=submit
<form method="POST">
<input name="try" required>
<button type="submit">button 1</button>
<button type="submit">button 2</button>
</form>
You can use formnovalidate
<form method="POST">
<input name="try" required>
<button type="submit">button 1</button>
<button type="submit" formnovalidate>button 2</button>
</form>
Using some simple Javascript should allow you to use button two but ignore the required attribute assigned to the text field.
document.querySelectorAll('button')[1].addEventListener('click',function(e){
e.preventDefault();
this.parentNode.try.required=false;
this.parentNode.submit();
})
<h2>submit test</h2>
<form method="POST">
<input type="text" name="try" required />
<button type="submit">button 1</button>
<button type="submit">button 2</button>
</form>
Try
<form method="POST">
<input name="try" required>
<button type="submit">button 1</button>
<button type="submit" value="ignore" >button 2</button>
</form>

continue button and add button

I need you help, I have a form in PHP, javascript, HTML and MYSQL. I use a bootstrap for template.
I have a two button (continue button and add button)
<form class="form-horizontal form-label-left" action="PHP/GuardarMetodoque.php" method="POST" novalidate>
<div class="form-group">
<div class="btn-group btn-group-lg">
<button class="btn btn-primary" onclick="return continuar();">Continuar</button>
<button type="submit" class="btn btn-primary" onclick="return continuar();">Continuar</button>
<input type="hidden" name="metodoque" value="metodoque" />
<button type="submit" class="btn btn-primary" onclick="return continuar();">Añadir Riesgo</button>
<input type="hidden" name="Anadirriesgo1" value="Anadirriesgo1" />
<input type="hidden" name="ID_proceso" value="<?php echo $_id; ?>">
<input type="button" class="btn btn-primary" value="Regresar" onclick="history.back(-1)" />
</div>
</div>
</form>
the continue button serves to pass another page and the add me button works to add data from the answered form.
as you see called the file "PHP/GuardarMetodoque.php" and it works but when you click continue, you save the form again, and what I want is for you to just send me the other form without saving anything
If you set button type to submit for continue button it will submit the form to mentioned action url, Try:
<button class="btn btn-primary" id="continue">Continue</button>
Add jquery to handle button click event:
$('#continue').click(function(){
//do your logic here
});

jQuery form Validation does not include value of submit button

I'm using jquery form validation from http://www.runningcoder.org/jqueryvalidation/
demo.html
<form id="form-signup_v1" name="form-signup_v1" method="get" class="validation-form-container">
<div class="field">
<label for="signup_v1-username">First Name</label>
<div class="ui left labeled input">
<input id="first_name" name="first_name" type="text">
<div class="ui corner label">
<i class="asterisk icon">*</i>
</div>
</div>
</div>
<input name="ok" id="ok" type="submit" class="ui blue submit button" value="Ok">
<input name="cancel" id="cancel" type="submit" class="ui blue submit button" value="Cancel">
</form>
<script>
$('#form-signup_v1').validate({
submit: {
settings: {
inputContainer: '.field'
}
}
});
</script>
I'm use form validation in the url not include the value of submit button
demo.html?first_name=John
I try to remove jquery form validation in the url include the value of submit button
demo.html?first_name=John&ok=OK
I want to check submit button when click from query string but when i use validation the url alway not include query string of button like the figure 1
If you want that the query doesn't include the button name just remove the name attribute from <input type = "button" name="ok">. Also assign a value to the button. By default the submit action forms the query string from the name value pairs in the form.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<form action="get">
<input name="first_name" type="text" />
<input type="submit" value="button">
</form>

Form being submitted on clicking image

Here is my code:
<form action="telecallerinfo.php?action=modify&id=<?php echo $id;?>" method="post" enctype="multipart/form-data">
<table class="panel1">
<tr>
<td>Caller Name: <input name="tele_caller" type="text" size="15" value="<?php echo $tele_caller?>" /></td>
</tr>
<tr>
<td align="right">
<input name="submit" id="submit" type="image" src="images/submit.gif" width="60" onclick="this.form.submit();"/>
<input name="cancel" id="cancel" type="image" src="images/cancel.gif" width="60" onclick="window.location.href='telecallerinfo.php';"/>
</td>
</tr>
</table>
</form>
but then I am clicking on the cancel image. The form is being submitted. How to stop it because I want only the page to be refreshed. Is there any way of giving reset functionality to an image?
Image inputs submit the form when clicked. You need to return false in your event handler to stop the normal action of the button taking place.
<input name="cancel" id="cancel" type="image" src="images/cancel.gif" width="60" onclick="window.location.href='telecallerinfo.php'; return false;"/>
In theory the same should hold for the submit-image, but actually you should just discard the event handler and let the default action submit the form when clicked.
For a button that just navigates to a page you would be better off using a simple link.
Is there any way of giving reset functionality to an image?
If you really wanted:
<img onclick="document.getElementById('someform').reset();">
But it'd be better to do it without JS using a real reset button:
<button type="reset">
<img src="images/cancel.gif" alt="Reset"/>
</button>
This will give you a button graphic around the image, but you can get rid of that with CSS:
border: none; padding: 0; margin: 0; background: transparent;
Are you sure you want a ‘reset’? They're rarely useful, and often annoying if accidentally clicked thinking they're submit buttons...
<img src="images/cancel.gif" alt="DON'T FORGET ALTERNATIVE TEXT">
You may try this if you want it as an image:
<button type="reset">
<img src="image location" alt="Reset" />
</button>
It works but, RESET buttons are destructive and should not
be used, except in situations where destruction of user input is really
desirable.
<input type="reset" name="Reset" id="button" value="Reset" />
Just try this one
<input type="image" src="butup.gif" alt="Submit button">
Some browsers wont support to "alt" tab so there is another way:
<html>
<body>
<form action="example.cgi" method="post">
<input type="text" name="login">
<br>
<input type="image" src="submit.gif">
<input type="image" src="reset.gif">
</form>
</body>
</html>

Categories