jQuery / Javascript - submit form when checkbox is clicked [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a page where I display results form database and there are checkboxs which filter ther results. The problem is that I don't want to use submit button because I would like to let the user only click on the checkboxes to get the desired results. So is there anyway using javascript or jquery to submit a form when checkbox is checked with no submit button? if you see on shopping sites there are no submit buttons just the checkboxes..Like that. thanks
<form>
<input type="checkbox" name="size" > Size
</form>
here is the php
<?php if (isset($_POST["size"])){
//do something
?>

<form id="form" method="post" action="">
<input type="checkbox" name="checkbox" class="checkbox"/>
</form>
<script type="text/javascript">
$(function(){
$('.checkbox').on('change',function(){
$('#form').submit();
});
});
</script>
OR
<form id="form" method="post" action="">
<input type="checkbox" onchange="$('#form').submit();" name="checkbox" class="checkbox"/>
</form>

$(input:name=[checkboxname]).change(function(){
$('#form').submit();
});
alternately
$('#checkboxId').click(function(){
$('#formId').submit();
});
of course additional parameters can be passed withing the submit() function for ajax, etc.

Related

How to create 'add quantity' input box and embed it inside PHP scripts? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 years ago.
Improve this question
Thanks for those who helped! I have figured it out!
How can I create a input field like the one in the image? And I want to embed it inside $_POST. Thanks for your time :)
This is an HTML5 input of type number. You use it this way:
<form method="POST" action="yourPHPfile.php">
<input type="number" name="number_input">
<input type="submit">
</form>
When this form is submitted, it will send the selected number to yourPHPfile.php and you can retrieve the number from $_POST['number_input']
You can use input for the number selecotr and post using a form like so:
<form method="post">
<input type="number" name="intNumber"/>
<input type="submit" />
</form>
Then in PHP you can do this
<?PHP
if(isset($_POST['intNumber'])){
$myNumber = $_POST['intNumber']; // intNumber is the name of of your input
}
?>
When the submit button the PHP will be fired.
Hope this helps!

HTML5 form button onsubmit not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have a simple form with two HTML5 buttons. Each button submits the form to a different php page. This is working well, but the 'onsubmit' function is never triggered. I want to show a dialog box before the delete.php page is called.
<form method="post">
<input type="text" name="fname">
<!-- HTML5 FORMACTION -->
<button type="submit" name="update" formaction="update.php">Update</button>
<button type="submit" name="delete" onsubmit="return confirm('Do you really want to delete?');" formaction="delete.php">Delete</button>
</form>
I have tried different variations, but the javascript code is never triggered. Why?
Buttons don't have submit events, forms do.
Buttons have click events.
onsubmit is valid for a form, not for a button. You will have to use onclick instead of onsubmit.
try like this
<form method="post">
<input type="text" name="fname">
<!-- HTML5 FORMACTION -->
<button type="submit" name="update" formaction="update.php">Update</button>
<button type="button" name="delete" onclick="return delete();" formaction="delete.php">Delete</button>
</form>
<script>
function delete(){
if(confirm('Do you really want to delete?')){
// delete code
}
return false;
}
</script>

Php form submit alert if less than 1min passed [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I need some help with my php code
<?php
date_default_timezone_set('America/Los_Angeles');
$now = date("H:i:s");
?>
<form method="post" name="update" action="update.php" />
<input type='text' name='fname' value=''>
<input type='text' name='lname' value=''>
<input type='text' name='email' value=''>
...
<button type="submit" value="Submit"/> Submit </button>
</form>
What i need:
If someone clicks on button submit but it passed less than 1 min since start($now)
then it must appear an Alert "Check Info"(not another page or popup),
an alert like "Do you really want to leave the page?"
I should not work for free... but I won't give you the full answer!!! Make an effort and fill in the right code <<< FILL >>> to get it to work!!!
<script src="<<<FILL>>>"></script>
<script>
submitAllowed = false
$("form").submit(function(e){
e.preventDefault();
if (<<<FILL>>>||confirm("Do you really want to leave")) {
this.submit()
}
});
function submitAttempt(){
submitAllowed = true;
}
setTimeout(<<<FILL>>>, 60000);
</script>

How do I allow a user to submit multiple instances of the same form on a page and store the data using php? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I am working on a php project that consists of an html form that allows the user to submit the bits of text, a song name, composer, and artist. Once the user fills in the form and clicks submit, the data should be stored and allow the form to be filled in again until the user pushes another button which shows all of the data that has been submitted. I have so far thought of using arrays, but I am not sure how that would work with multiple form submissions sending to the same array. Any help would be greatly appreciated.
<html>
<head>
</head>
<body>
<form method="post">
Name of song: <input type="text" name="songName"><br>
Composer: <input type="text" name="composer"><br>
Artist/Group: <input type="text" name="artist"><br>
<input type="submit" name="submit">
</form>
</body>
<?php
if (!empty($_POST['submit'])) {
//Submit the data into the array or something here
}
?>
</html>
Certainly, try this and see what happens:
<?php
session_start();
// Initialize an array for answers
if (!isset($_SESSION['answers']))
$_SESSION['answers'] = array();
?>
<html>
<head>
</head>
<body>
<form method="post">
Name of song: <input type="text" name="songName"><br>
Composer: <input type="text" name="composer"><br>
Artist/Group: <input type="text" name="artist"><br>
<input type="submit" name="submit">
</form>
</body>
<?php
if (!empty($_POST['submit'])) {
// Push the posted data into the session array
$_SESSION['answers'][] = $_POST;
}
// Display the data now
foreach($_SESSION['answers'] as $array) {
echo "Name of song: {$array['songName']}<br>";
echo "Composer: {$array['compose']}<br>";
echo "Artist/Group: {$array['artist']}<br><hr>";
}
?>
</html>
Note: SESSIONS only remain until the user logs off or they time out. For persistance over long periods, you need to use a database such as MySQL to store the answers

Change inner text and class when submitting in a form? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Is there any way to change the inner text of tag when the form is subbmitting?
For example, I have this HTML code:
<form>
<button>Submit</button>
</form>
When I click to the button or press Enter key, the submit text will change to processing or something like that. A class will be added to the button element..etc.
What element do you want to change? You can identify it a number of ways. The most common ways are by ID or class
$('form').submit(function(){
$('#element_id').text('what_you_want_to_write');
$('#element_id').attr('class', 'new_class_name');
return false;
});
Or, you can change the class name by doing
$('#element_id').addClass('new_class_name');
you can add a handler to the submit event of the form like
$('form').submit(function(){
$(this).find('button').text('Processing');
//form submission logic goes here if any
})
Change html:
<form>
<button id="submitButton" onclick="changeText()">Submit</button>
</form>
Javascript:
<script>
function changeText()
{
document.getElementById("submitButton").innerHTML="Processing...";
}
</script>
Try this
code
$(document).ready(function () {
$('#submit').click(function (e) {
$(this).val("Processing....");
$(this).addClass('processing');
$('#frm1').submit();
});
});
html
<form id="frm1">
<input type="button" value="submit" id="submit"/>
</form>
css
.processing
{
background:blue;
color:white;
}

Categories