SweetAlert2 message show issue

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
ebinnasir
User
Posts: 103

SweetAlert2 message show issue

Post by ebinnasir »

Hi,

Hope all are in good health.

In my form there are a field named "machne_no". I want to show sweetalert2 message once user input value in that text field. I wrote below javascript code fulfill my requirement.

{ // keys = event types, values = handler functions
	"change": function(e) {
		// Your code

 //Pass the id of the <input> element to be copied as a parameter to the copy()
let copyText = (mechine_no) => {
  //Selects the text in the <input> elemet
  document.getElementById(mechine_no).select();
  //Copies the selected text to clipboard
  document.execCommand("copy");
};

var batch_id = $mysqli -> query("SELECT grd_batch_no FROM production where machine_no = copyText.value AND dyeing_started = "Yes" AND dyeing_complete = "No"") 

var job_queue = $mysqli -> query("SELECT COUNT(grd_batch_no) FROM production where machine_no = copyText.value AND dyeing_started = "No" AND dyeing_complete = "No"")

var machine_occupancy = $mysqli -> query("SELECT loading_time FROM production where machine_no = copyText.value AND dyeing_started = "Yes" AND dyeing_complete = "No"") // return full datetime, eg: 2023-5-20 13:55:21

var wait_time = $mysqli -> query("SELECT SUM(MINUTE(required_hour)) FROM production where machine_no = copyText.value AND dyeing_started = "No" AND dyeing_complete = "No"") 
		function add() {
		setInterval(() => {
        // let currentTime = new Date().getTime();
         let queueTime = new Date(machine_occupancy + wait_time / 60);
         
      Swal.fire(
  'Machine No: copyText.value is occupied for batch no: batch_id.value.',
  'Number of batch in the job queue is: job_queue.vaule ',
  'Approximately waiting time: wait_time Hours ',
  'Approximately schedule time for your batch: queue_time.value: ', // want to show full datetime, eg: 2023-5-20 13:55:21
  'question'
  			)
	}
}

There are programming mistakes on my code. Can anyone help me to formulate codes on the write way?

Thanks in advance .


mobhar
User
Posts: 11702

Post by mobhar »

You cannot use PHP code in Client Side Events section.

You should create your own API Action from server-side, and then from Client Side Events, you may use Ajax by API and Client Scripts.


ebinnasir
User
Posts: 103

Post by ebinnasir »

Are there any other alternative way to get the same result as i don't know how to write API codes?


arbei
User
Posts: 9354

Post by arbei »

You have mixed PHP code and JavaScript together. Note that SweetAlert2 is client side JavaScript, while API is server side PHP. When you need data from the server side without reloading the page, you should use Ajax. If you don't know it yet, you may learn it, as mobhar wrote:

You should create your own API Action from server-side, and then from Client Side Events, you may use Ajax by API and Client Scripts.


mobhar
User
Posts: 11702

Post by mobhar »

ebinnasir wrote:

i don't know how to write API codes

It's not difficult to write API code. Just refer to the code in the documentation from the link mentioned above. You should be able to do that by yourself. Always try it first, and you may post your code for more discussion.


Post Reply