Jump to content

Can a javascript function called via onclick use jquery?


fatkatie

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.