Hi Marc,
On Sat, 11 Sep 2010 08:37:59 -0400, Marc Delisle marc@infomarc.info wrote:
Hi, this works on a input element:
var this_name = $(this).attr('name');
so I'm trying to do the same to extract the code inside the onchange "attribute":
var this_onchange = $(this).attr('onchange');
this won't work.
but Firebug tells me that this_onchange is an event;
yepp that's right
it does not contain the code. I need to do subsequent string matching and replacement in this code.
Please use a function call for this, and replace silly the params: $(this).unbind('change'); $(this).bind('change', function(e) { // your function call // something like: // pma_js_function_to_call(param1, param2, para,X) });
Other solution is to work with a string, make your string replacement and after this use the eval-function. Sample: $(this).unbind('change'); $(this).bind('change', function(e) { eval(your_replaced_string); });
But eval is devil: The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.
Regards Michael
Michael Keck a écrit :
Hi Marc,
On Sat, 11 Sep 2010 08:37:59 -0400, Marc Delisle marc@infomarc.info wrote:
Hi, this works on a input element:
var this_name = $(this).attr('name');
so I'm trying to do the same to extract the code inside the onchange "attribute":
var this_onchange = $(this).attr('onchange');
this won't work.
but Firebug tells me that this_onchange is an event;
yepp that's right
it does not contain the code. I need to do subsequent string matching and replacement in this code.
Please use a function call for this, and replace silly the params: $(this).unbind('change'); $(this).bind('change', function(e) { // your function call // something like: // pma_js_function_to_call(param1, param2, para,X) });
Other solution is to work with a string, make your string replacement and after this use the eval-function. Sample: $(this).unbind('change'); $(this).bind('change', function(e) { eval(your_replaced_string); });
But eval is devil: The eval function (and its relatives, Function, setTimeout, and setInterval) provide access to the JavaScript compiler. This is sometimes necessary, but in most cases it indicates the presence of extremely bad coding. The eval function is the most misused feature of JavaScript.
Regards Michael
Thanks, this should help me!
Michael Keck a écrit :
Hi Marc,
On Sat, 11 Sep 2010 08:37:59 -0400, Marc Delisle marc@infomarc.info wrote:
Hi, this works on a input element:
var this_name = $(this).attr('name');
so I'm trying to do the same to extract the code inside the onchange "attribute":
var this_onchange = $(this).attr('onchange');
this won't work.
but Firebug tells me that this_onchange is an event;
yepp that's right
it does not contain the code. I need to do subsequent string matching and replacement in this code.
Please use a function call for this, and replace silly the params: $(this).unbind('change');
Michael, I also need to do .attr('onchange', '')
otherwise the code inside onchange executes.
$(this).bind('change', function(e) { // your function call // something like: // pma_js_function_to_call(param1, param2, para,X) });
Am 12.09.2010 13:42, schrieb Marc Delisle:
Michael, I also need to do .attr('onchange', '')
otherwise the code inside onchange executes.
Okay, but this is not really jQuery?! Unbinding an event should do it: $('#id_of_the_element').unbind('change'); And binding a new event: $('#id_of_the_element').bind('change', function() { ... });
Perhaps you can try: $('#id_of_the_element').bind('change', null);
Michael
Michael Keck a écrit :
Am 12.09.2010 13:42, schrieb Marc Delisle:
Michael, I also need to do .attr('onchange', '')
otherwise the code inside onchange executes.
Okay, but this is not really jQuery?!
Indeed, we still have legacy js code like onchange and onclick; it would take time to remove it all.
Unbinding an event should do it: $('#id_of_the_element').unbind('change'); And binding a new event: $('#id_of_the_element').bind('change', function() { ... });
Perhaps you can try: $('#id_of_the_element').bind('change', null);
Michael