{"id":47,"date":"2010-03-03T06:45:00","date_gmt":"2010-03-03T06:45:00","guid":{"rendered":"http:\/\/www.codeboss.in\/web-funda\/?p=47"},"modified":"2010-03-03T06:45:00","modified_gmt":"2010-03-03T06:45:00","slug":"how-to-change-value-of-onclick-event-dynamically-with-javascript","status":"publish","type":"post","link":"https:\/\/codeboss.in\/web-funda\/2010\/03\/03\/how-to-change-value-of-onclick-event-dynamically-with-javascript\/","title":{"rendered":"How To Change Value Of OnClick Event Dynamically With JavaScript"},"content":{"rendered":"<p>The following script changes the onclick event of the button &#8220;Test&#8221; dynamically according to which radio button is selected. The JavaScript function changeOnClick() changes the event dynamically.<\/p>\n<pre class=\"brush: html;\">\n<input type=\"radio\" name=\"choice\" onclick=\"changeOnClick('hi')\" \/>&nbsp;Hi!\n<input type=\"radio\" name=\"choice\" onclick=\"changeOnClick('hello')\" \/>&nbsp;Hello!\n<input type=\"radio\" name=\"choice\" onclick=\"changeOnClick('bye')\" \/>&nbsp;Bye!\n\n<input type=\"button\" id=\"buttonid\" onclick=\"funchi()\" value=\"Test\" \/>\n\n<script type=\"text\/javascript\">\nfunction funchi(){\nalert(\"Hi!\");\n}\nfunction funchello(){\nalert(\"Hello!\");\n}\nfunction funcbye(){\nalert(\"Bye!\");\n}\nfunction changeOnClick(wh){\ndocument.getElementById('buttonid').onclick = new Function(\"func\"+wh+\"()\");\n}\n<\/script>\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following script changes the onclick event of the button &#8220;Test&#8221; dynamically according to which radio button is selected. The JavaScript function changeOnClick() changes the event dynamically. &nbsp;Hi! &nbsp;Hello! &nbsp;Bye!<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[14],"tags":[51],"class_list":["post-47","post","type-post","status-publish","format-standard","hentry","category-javascript","tag-javascript-2","entry"],"_links":{"self":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/47","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/comments?post=47"}],"version-history":[{"count":0,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/posts\/47\/revisions"}],"wp:attachment":[{"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/media?parent=47"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/categories?post=47"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codeboss.in\/web-funda\/wp-json\/wp\/v2\/tags?post=47"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}