{"id":685,"date":"2022-08-30T15:05:28","date_gmt":"2022-08-30T15:05:28","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/calling-different-url-based-on-button-value-using-jquery-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:05:28","modified_gmt":"2022-08-30T15:05:28","slug":"calling-different-url-based-on-button-value-using-jquery-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/calling-different-url-based-on-button-value-using-jquery-collection-of-common-programming-errors\/","title":{"rendered":"calling different URL based on button value using jquery-Collection of common programming errors"},"content":{"rendered":"<p>I have a button that calls a CFM page and it needs to pass a value depending on whether the user is activating or deactivating a record from the database. I&#8217;m struggling with how to pass the active\/inactive value into jQuery. Below is the code I&#8217;m using, which only works one-way, that is from active to inactive.<\/p>\n<pre><code>\n$(document).ready(function() {\n\n    $(\"#IsActive_1\").click(function() {\n\n    \/\/cache the status div\n        var status = $(\"#status\");\n\n        \/\/let the user know the record is being updated\n        status.html(\"<i>updating status...<\/i>\");\n\n    $(\"#IsActive_1\").html('activate');\n\n        \/\/the status variable needs to be dynamic\n        $.get(\"updateStatus.cfm?status=inactive\", {}, function(res,code) {\n        \/\/show the result in plain HTML\n        status.html(res);\n    });\n\n    });\n\n});\n\n\n\ndeactivateactivate\n<\/code><\/pre>\n<p>Lastly, I would like to change the text displayed on the button to activate\/deactivate based on the proper condition (activate after clicking deactivate and viceversa).<\/p>\n<p>TIA<\/p>\n<ol>\n<li>\n<p>You can add an attr to the button, and based on it, send the variable.<\/p>\n<pre><code>Deactivate\n\n\n    $(\"#IsActive_1\").click(function() {\n          var x = $(this);\n          var isActive = x.attr('checked') != undefined;\n          if (isActive)\n            x.removeAttr('checked');\n          else\n            x.attr('checked', 'checked');\n        \/\/cache the status div\n            var status = $(\"#status\");\n\n            \/\/let the user know the record is being updated\n            status.html(\"<i>updating status...<\/i>\");\n\n             x.html(isActive ? 'Activate' : 'Deactivate');\n\n            \/\/the status variable needs to be dynamic\n            $.get(\"updateStatus.cfm\", { status : isActive ? 'inactive' : 'active' }, function(res,code) {\n            \/\/show the result in plain HTML\n            status.html(res);\n        });\n\n        });\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-11-09 21:39:01. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I have a button that calls a CFM page and it needs to pass a value depending on whether the user is activating or deactivating a record from the database. I&#8217;m struggling with how to pass the active\/inactive value into jQuery. Below is the code I&#8217;m using, which only works one-way, that is from active [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-685","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/685","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=685"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/685\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=685"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=685"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=685"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}