fatkatie Posted February 10, 2019 Share Posted February 10, 2019 The onclick event is set to call a javascript function. I need to use jQuery within that javascript function. Is that possible? Thank you. function updateStock(pn) { alert("here is the pn: " + pn); jQuery(document).ready(function() { alert("I want to see pn here: " + pn); }); } Quote Link to comment https://forums.phpfreaks.com/topic/308301-can-a-javascript-function-called-via-onclick-use-jquery/ Share on other sites More sharing options...
maxxd Posted February 10, 2019 Share Posted February 10, 2019 Yes. Depending on how everything is set up and when and where the function is defined you may have to pass jQuery to the function, but it's easily doable. For instance (and please note it's late and this hasn't been tested so ... you know, look up the functions but the idea is solid) this: $('#mycontrol').on('click', function(e){ e.preventDefault(); $.post({ // ....etc etc... }); }); Quote Link to comment https://forums.phpfreaks.com/topic/308301-can-a-javascript-function-called-via-onclick-use-jquery/#findComment-1564350 Share on other sites More sharing options...
fatkatie Posted February 10, 2019 Author Share Posted February 10, 2019 I had no idea! Scope, closure, hoisting ... I really don't know this stuff. I did get the function parameter pn into the jQuery part by simply assigning it as in (ff65): function updateStock(pn) { alert("here is the pn: " + pn); var mypn = pn; jQuery(document).ready(function() { alert("I want to see pn here: " + mypn); }); } Lots of reading and re-reading to do. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/308301-can-a-javascript-function-called-via-onclick-use-jquery/#findComment-1564366 Share on other sites More sharing options...
kicken Posted February 10, 2019 Share Posted February 10, 2019 You shouldn't even need to assign it to a new mypn variable like that. your original code where you just used pn directly should work just fine. Quote Link to comment https://forums.phpfreaks.com/topic/308301-can-a-javascript-function-called-via-onclick-use-jquery/#findComment-1564367 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.