I have a form (HTML) with some inputs (checkbox) and I want to submit only inputs that user has clicked ou unclicked and ignore the others inputs.
I'm thinking in add a class (javascript) to the input when user change value. But I don't know if it is a good ideia.
Any Suggestions?
You can have the form that submits onClick() and calls a Javascript. When that happens you then search what values have been unchecked and then use the Javascript to submit it to the next page to handle the response.
However not sure what you are trying to achieve doing this...
Class approach is working.
When user click on input I add class "envia":
$("INPUT[type='checkbox']").click(function(){
$(this).addClass("envia");
});
On submit I send only data with the class I want:
$.post("/financeiro/funcional/contasapagar.php", $(".envia").serialize(), function(data){
//code here
});
Only data the user changed is send to server.
Related
I have a form with multiple inputs. I'm trying to specifically send text inputs to a function and have the function return the var as a table. I am able to send the input and return a table, but the table only appears for a brief second when I click a submit button, then the page seems to refresh. I have the submit input set to onclick="function()".
Does anybody have any ideas as to why after I click submit, the page refreshes and I loose the data in the table? I would appreciate some ideas of what the proper way is to go about this problem. Thanks in advance.
you can use onclick="function(event){event.preventDefault(); /*your code here*/}" to cancel the refresh
One option might be to use a regular button instead of a submit button:
<button onclick="function()">Function</button>
By the way, I really hope your function isn't actually called function(), but that's a whole other problem...
When the user clicks the submit button, I was to pop-up a confirm box. My problem is that when he presses OK, I want to run one query. When he presses Cancel, I want to execute a different query.
Can this be achieved with only PHP and JavaScript (Not AJAX or JQuery)
If Yes, Please tell me how. Thanks.
Edit: My main problem is that if I attach the onclick function to submit button, it is executing the server side code before taking the confirmation. And I cannot add the onsubmit function to the form since I have two action items associated with this and I want this feature for only one button. Any thoughts on this?
Create a hidden input field. Based on user's selection set it to different values using JS and then parse those values using php script to identify what should be done
Use Hidden field for user selected value like OK or Cancel.Change the query based on the user selected value.
You can call confirm()
function myfunc1(id) {
if (confirm("OK to submit?")) {
location.href = 'delete.php?id='+id;
}else{
// somthing else
}
}
Or you can call it in the onclick:
onclick="if (confirm('OK to submit?')) { myfunc1('<?php echo $uid;?>'); } "
use this way...
<input type="submit" onclick="return confirm('Are you sure?');" value="submit" >
//if user click ok then your form will submited otherwise if user click cancel it does nothing .
may be this will help
I have input field
<input type="text" name="vehicle_make[]" id="make1"/>
and i have help dropdown that updates this field if user choose to do so. I do it trough standard jquery code
$("#make1").val("value");
Problem is, since i use validate plugin to validate this field, if user click on validate before entering anything in that box, he will get notice that he needs to fill it, but then if he fills it trough dropdown, validate plugin will not detect it until user click on submit again.
I know i could call submit in function in which i process dropdown, but i think that it is not right solution, since i would need to check if validation is already done before doing that (since if it is not, it would start validation before i want it to start).
I also need to tie some other things to that field also, so i would like to know is there is a way in which i could write function so it always check if field is filled, even if user did not fill it directly.
Sorry if i didn't explain everything right, this is my first message here.
Try this
$("#make1").change(function(){
//do something there
});
I have found solution. First, i created js variable form_submitted, and added onclick event to submit button, to change value of variable form_submitted to yes. Then, i created function:
function update_validation(){
if(form_submitted == 'yes'){
$("#my_form").valid();
};
};
that i call when user do something that is not detected regularly with validate plugin. This function manually starts validation again, but only if it has been started before by clicking on submit.
i have 20 checkboxes in usercontrol ... i wanna do whole coding in user control ...
how to show msg box if user forgot to check asp.net checkbox control on button click .. ?
You should provide a CustomValidator for every Checkbox which validates on client- and serverside if the Checkbox is checked.
http://www.joe-stevens.com/2009/08/12/using-the-customvalidators-clientvalidationfunction/
Create a public method on the user control that returns a boolean indicating if the data entry in the control is correct. Call that method from your page on the button click event. If data entry is valid, continue processing;else show an error message.
Is there a way in AJAX or JS to add further inputs upon a button click?
In short, yes you can add more inputs on a button click.
For example, in jQuery, you could have something like this where the buttonID is the id attribute for the button and the formID is the id attribute for your form:
$("buttonID").click(function() {
//add new inputs here, something like:
$("formID").append('<input type="text" id="newInput" name="newInput" />');
});
You can also have the additional inputs hidden to start off with and then 'un-hide' them on a click if you want.
Further inputs? Run any JavaScript you want when a user clicks a button by adding an event listener to the button that listens for a click.
Once a user clicks on the button, if you have an event listener, you can change what they had entered, you can do anything anything you want.
I am not certain what you mean by 'further inputs' though. If you are sending data then you can append whatever you want, I frequently append a timestamp to help prevent caching issues, for example.