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); }); } Link to comment 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... }); }); Link to comment 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 Link to comment 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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.