I am having issues using jquery to set the value a element which calls a function. Here is the code
Element:
each outlet in FBoutlets
br
label(for='FBoutlet') Facebook: #{outlet.FBoutlets.name}
input(type='checkbox', value='', onchange="streamFB(" + outlet.FBoutlets.FBpageId + "," + JSON.stringify(outlet.FBoutlets.FBaccessToken) + ")", name='FBoutletCredentials', id='FBoutlet')
Function:
script.
window.fbAsyncInit = function() {
FB.init({
appId : '20212222222',
autoLogAppEvents : true,
xfbml : true,
version : 'v2.12'
});
};
function streamFB(pageId, accessToken){
FB.api(
'/' + pageId + '/live_videos',
'POST',
{access_token: accessToken},
function(response) {
let rtmp = response.stream_url
console.log(rtmp)
console.log(response)
$(this).val() = rtmp;
}
);
}
$(this).val() is returning undefined, I need to use this because the element id dynamically generated
You should change it
$(this).val() = rtmp;
to
$(this).val(rtmp);
jquery val function takes argument value as assigning value
The val() method returns or sets the value attribute of the selected elements.
This method returns the value of the value attribute of the FIRST matched element.
This method sets the value of the value attribute for ALL matched elements.
Note: The val() method is mostly used with HTML form elements.
Return the value attribute:
$(selector).val()
Set the value attribute:
$(selector).val(value)
Set the value attribute using a function:
$(selector).val(function(index,currentvalue));
value Required. Specifies the value of the value attribute function(index,currentvalue) Optional. Specifies a function that returns the value to set. index - Returns the index position of the element in the set currentvalue - Returns the current value attribute of selected elements
source:https://www.w3schools.com/jquery/html_val.asphttps://www.w3schools.com/jquery/html_val.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With