0

I create a button, then the button is supposed to triggered a JS function that will call another JS function. I tried to put Alert function in JS to test if it triggered, but it didn't. Anyone can help me?

Why it didn't get triggered?

$(document).ready(function() {
  $("#btnProcess3").attr("disabled", "disabled");
  alert("hi")
  jsProcess(0);

  $("#btnProcess3").click(function() {
    alert("hi")
    $(this).attr("disabled", "disabled");
    jsProcess(1);
  });
});

function jsProcess(action) {
  var page;
  var sDate;
  var sBizDate;
  sDate = $('#txtDate').val();

  if ($('#chkuseBizDate').is(':checked')) {
    sBizDate = $('#txtBizDate').val();
  } else {
    sBizDate = sDate;
  }
  page = "LoadPPSFile_details01.asp?TaskId=<%=sTaskId %>&txtDate=" + (sDate) + "&RunProcess=" + action + "&txtBizDate=" + (sBizDate);
  document.getElementById("IProcess").src = page;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input type="button" name="btnProcess" id="btnProcess3" value="Start - Services" width="250" style="VISIBILITY:show; WIDTH: 150px; HEIGHT: 22px; Background-Color:#1E90FF; Border-Color:white; Color:white; Font-Weight:bold;Font-family:Verdana;Cursor:hand; "
/>

5
  • 2
    As this seemingly has nothing to do with C#, VB or VBA I've edited the question to remove reference to them Commented Jan 23, 2023 at 14:50
  • Also, it looks like you have some server-side code in your JS. Ensure you're running this JS code in a location where this will be interpreted correctly, ie. NOT in a .js file Commented Jan 23, 2023 at 14:52
  • 3
    That because you on document ready disable that button by $("#btnProcess3").attr("disabled", "disabled"); . So remove this line then retry!! Commented Jan 23, 2023 at 14:53
  • 2
    How do you click a disabled button? A disabled button is not going to register a click event. Commented Jan 23, 2023 at 14:55
  • but i have a button that used the same structure of code. Attribute Visibility:Show in the HTML code should enable the JS right? I copy the same structure from other code in my project, that's why i confused with this one. Also, i have tried to change the JS to : $("#btnProcess3").attr("disabled", false); but it still didn't triggered the JS :/ Commented Jan 24, 2023 at 5:03

1 Answer 1

1

Your code is missing some code that the jsProcess() is looking for, but the Button performs as excepted, when you remove the Disabling part.

$(document).ready(function() {
  // $("#btnProcess3").attr("disabled", "disabled");
  // alert("hi")
  // jsProcess(0);

  $("#btnProcess3").click(function() {
    alert("I'm triggered!")
    $(this).attr("disabled", "disabled");
    // jsProcess(1);
  });
});

function jsProcess(action) {
  var page;
  var sDate;
  var sBizDate;
  sDate = $('#txtDate').val();

  if ($('#chkuseBizDate').is(':checked')) {
    sBizDate = $('#txtBizDate').val();
  } else {
    sBizDate = sDate;
  }
  page = "LoadPPSFile_details01.asp?TaskId=<%=sTaskId %>&txtDate=" + (sDate) + "&RunProcess=" + action + "&txtBizDate=" + (sBizDate);
  document.getElementById("IProcess").src = page;
}
#btnProcess3 {
  VISIBILITY: show;
  WIDTH: 150px;
  HEIGHT: 22px;
  Background-Color: #1E90FF;
  Border-Color: white;
  Color: white;
  Font-Weight: bold;
  Font-family: Verdana;
  Cursor: hand;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.1/jquery.min.js"></script>
<input type="button" name="btnProcess" id="btnProcess3" value="Start - Services" width="250">

Sign up to request clarification or add additional context in comments.

2 Comments

hey i tried your code in my project, it didn't trigger the Alert function even though it tested okay in 'Run code snippet'. i'm confused
hey i just found out the solution, first the code is incorrect like you mentioned. then i need to clear the cache. thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.