1

I am new to JavaScript, I am trying to call another function but it is not working can someone tell me what am doing wrong. I have a radio button based on the selection i want to call a function.

  const paymentForm = document.getElementById('paymentForm');
  paymentForm.addEventListener("submit", myFunction, false);

 //PaymentMethodRadio: 


 function myFunction() {
 if (document.getElementById('Once').checked) {
  payWithPaystack1.call();

  }

  if (document.getElementById('Reoccuring').checked) {

  }
}

   function payWithPaystack1(e) {
     e.preventDefault();
     let handler = PaystackPop.setup({

key: 'censored', // Replace with your public key
email: document.getElementById("email-address").value,
amount: document.getElementById("amount").value * 100,
ref: '' + Math.floor((Math.random() * 1000000000) + 1), // generates a pseudo-unique reference. Please replace with a reference you generated. Or remove the line entirely so our API will generate one for you
// plan: 'censored',
subaccount: 'censored',

// label: "Optional string that replaces customer email"

onClose: function () {
  alert('Window closed.');
},


callback: function (response) {
  let message = 'Payment complete! Reference: ' + response.reference;
  alert(message);
}
 });
  handler.openIframe();
  }
tacoshy
  • 10,642
  • 5
  • 17
  • 34
  • Please be more carefull what code your post here. Espacially if you post key, telefon-numbers, email-adresses or simliars it will be visible to everyone and pose a serios security risk! – tacoshy May 08 '22 at 19:44
  • Does this answer your question? [How to get the selected radio button’s value?](https://stackoverflow.com/questions/9618504/how-to-get-the-selected-radio-button-s-value) – kmoser May 08 '22 at 19:47
  • I am able to determine what was selected, however I want to call a function but it does not call. – Chizom Wornu May 08 '22 at 19:51

2 Answers2

0

Try to use on or changed events

 $(document.getElementById('Reoccuring')).on('click change', function(e) {
    
  // your checking statements.
  if (document.getElementById('Reoccuring').checked) {
      //checked function 
  } else
  {
      // unchecked
  }
});
Stuart.Sklinar
  • 3,683
  • 4
  • 35
  • 89
0

with If statement like this

if(document.getElementById('radioButtonID').checked) {
// do this
}

check this stack it may help How can I check whether a radio button is selected with JavaScript?

  • This works for me but when type this in, it does not go to the function "payWithPaystack1.call();" it does not go to the function. I added an alert to show that the if condition works. In side the if statement i want to call this function "payWithPaystack1.call();" but it does not work – Chizom Wornu May 08 '22 at 20:26