Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
53
rated 0 times [  58] [ 5]  / answers: 1 / hits: 45430  / 12 Years ago, fri, march 30, 2012, 12:00:00

How can I with js or jQuery change input text value with js or jQuery before submit if the input value is null ?



Thanks for help.


More From » jquery

 Answers
16

With jQuery, you can bind a callback to the submit event with the .submit() method.



$(form).submit(function(){
// Let's find the input to check
var $input = $(this).find(input[name=whatever]);
if (!$input.val()) {
// Value is falsey (i.e. null), lets set a new one
$input.val(whatever you want);
}
});


Notice: To ensure that all the elements can be found it should be placed in a domready function.


[#86512] Thursday, March 29, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
louiemarvinm

Total Points: 473
Total Questions: 103
Total Answers: 94

Location: Samoa
Member since Mon, Nov 8, 2021
3 Years ago
;