With jquery, I want to use the value of the function processing result (or variable defined in the function) in the change or click event in another process.
How should I set the return value?
* Reason: To handle the variable with ajax communication.
// Substitute the value of input and textarea updated in the browser to the variable
$('# id_url'). change (function () {
var inputVal_url = $(this) .val ();
console.log (inputVal_url);
});
// assign the value of the radio button selected on the browser to the variable
$(". page_name_btn"). click (function () {
var radioVal_page_name = $("input [name = 'page_name']: checked"). val ();
console.log (radioVal_page_name);
-
Answer # 1
-
Answer # 2
I think yambejp's answer is enough, but
Ifyou don't want to or can't get it during ajax communication processing, can you assign it to a global scope variable?// Variable declaration in scope outside both events let inputVal_url, radioVal_page_name; // Substitute the value of input and textarea updated in the browser to the variable $('# id_url'). change (function () { // assign to global variable inputVal_url = $(this) .val (); console.log (inputVal_url); }); // assign the value of the radio button selected on the browser to the variable $(". page_name_btn"). click (function () { // assign to global variable radioVal_page_name = $("input [name = 'page_name']: checked"). val (); console.log (radioVal_page_name); // Other processing below? });
-
Answer # 3
Thank you all.
Also, sorry for the lack of background. m () mBecause it is an article editing screen, when the page is loaded, the value is reflected in the value of input and radio button.
Since it was necessary to get the value for the user to enter the change contents in the input field, it was obtained by change or click.Making use of global scope variables in miyabi_takatsuk's content
I was able to get the value to send safely with ajax.
Thank you very much.let inputVal_url, inputVal_wire_url, inputVal_project, textareaVal_coment, radioVal_page_name, radioVal_job, radioVal_style; // Substitute the value of input and textarea updated in the browser to the variable $('# id_url'). change (function () { inputVal_url = $(this) .val (); console.log (inputVal_url); }); // input and radio description continues ...
Related articles
- return value of c language function
- javascript - i want to get the result and implement the tweet function!
- javascript - i want to use a function with the same name as a string that is the value of a variable in an object in vuejs
- javascript - i want to express a function registered as a value using a method name for an object with an arrow function
- javascript - the return value becomes undefined with slice ()
- javascript - about the return value of async
- why is the code written when the value of the object is made into a function in javascript?
- i want to change the result of repetition with the value checked by javascript
- javascript - i want a function that returns a string to work in return
- php - function execution and return value after routing without framework
- c ++ - the result is different between the function using simd extension instruction and the ordinary function
- javascript - i don't know the value of this
- javascript - i want to reduce the image of the preview function
- embed a function with javascript argument in html generated from javascript
- typescript - react return value of array processing (filter)
- javascript - i want to replace a class component with a function component
- cannot set transform: rotate value from variable in javascript
- about javascript random function
- python - return does not return a value
- javascript value property and value attribute difference
- javascript : Slick.js centerMode not working in Safari
- javascript : JQuery SVG click event not working
- javascript : Hash in SHA512 without haemorrhoids in jQuery
- javascript : Error in asung js function
- javascript : How to make a slider like this on Slick?
- javascript : Question about Yandex Maps
- javascript : Add second jQuery modal window
- javascript : Saving a file in Windows-1251 encoding
- javascript : how to open a second modal window from one modal window
- javascript : Handle clicking on a part of a parent element that has no child blocks
I don't understand the meaning
If the data is passed during "ajax communication", you can refer to the value at that time
$('# id_url'). val ()
$("input [name = 'page_name']: checked"). val ()
I think there will be no changes or clicks