0

I have this HTML code, and I want to remove part of the onclick events (the part after the ;). How should I do this?

I already got the object in an array:

document.getElementById(labels[i].htmlFor)

HTML:

<td valign="top" nowrap="nowrap">
<input id="ui_cbSubParam_LimitsColumnsTo" type="checkbox" name="ui_cbSubParam_LimitsColumnsTo" checked="checked" onclick="ControlConditionalEnable23(true);setTimeout('__doPostBack(\'ui_cbSubParam_LimitsColumnsTo\',\'\')', 0)" />
<label for="ui_cbSubParam_LimitsColumnsTo">Use Default</label>
</td>
Liam
  • 27,717
  • 28
  • 128
  • 190
varrtto
  • 101
  • 2
  • 3
  • 11
  • 1
    You probably want to pull the onclick function out to a javascript file/script tag. Then you can set a condition to determine whether to run the second command or not – Ben McCormick Mar 13 '13 at 15:28

1 Answers1

1

you can just reset the onclick:

var btn = document.getElementById(labels[i].htmlFor);
if(btn.onclick == true) {
   btn.onclick = function () { ControlConditionalEnable23(true); };
};
Pete
  • 57,112
  • 28
  • 117
  • 166
  • Do you have any idea on how to get the name of the function already asigned to the onclick event? the '23' changes in every form. – varrtto Mar 13 '13 at 16:23
  • I think you can do something like btn.getAttribute('onclick') – Pete Mar 13 '13 at 16:32
  • then you may need this http://stackoverflow.com/questions/912596/how-to-turn-a-string-into-a-javascript-function-call – Pete Mar 13 '13 at 16:39
  • Im having some issues with getAttribute, I try btn.getAttribute("onclick").substring(aNumber) but it says the object doesnt support the method, then I try string(btn.getAttribute("onclick")) it says it's expecting an object... what does getAttribute return? – varrtto Mar 13 '13 at 18:35
  • the getAttrbute should return a string have a look at this: http://jsfiddle.net/FdPP2/2/ it shows how to get your function from the onclick and then fire it – Pete Mar 14 '13 at 10:09