Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I must call a PHP page with a Javascript command.

I developed a function that does almost exactly what I needed:

View code: Example 1

But in the last part where it makes me "view" (document.getElementById('showResult')) only the result, I need to do it in a way that instead calls me another PHP page, where it will execute the instructions passed in this page.

What I have tried:

JavaScript
//Example 1

function getCheckedValues() 
			{
				return Array.from(document.querySelectorAll('input[type="checkbox"]'))
						.filter((checkbox) => checkbox.checked)
						.map((checkbox) => checkbox.value);
				}

				const resultEl = document.getElementById('result');

						document.getElementById('showResult').addEventListener('click', () =>{
						resultEl.innerHTML = getCheckedValues();

});


PHP
//Local where to call via the function:


'Location: ../backofficeNew/Tests/controller/sendToPhysicianSampleID.php?idList=BIY53423' 


//Button

<button id="showResult">SEND</button>
    <br><br>
	<div id="result"></div> 
Posted
Updated 10-Dec-21 2:54am
v14

1 solution

Dear All,


After some tests I came up with a solution I needed. I will leave her with you.

The part that returns the values ​​that were selected in the checkboxes, I kept.

JavaScript
function getCheckedValues() 
			{
				return Array.from(document.querySelectorAll('input[type="checkbox"]'))
						.filter((checkbox) => checkbox.checked)
						.map((checkbox) => checkbox.value);
				}


What I would have to do: It was to call another PHP page through Javascript.
So I developed:

JavaScript
function sendToPhysician() {
	if (getCheckedValues() == "") {
      alert('Please, select at least one row');
	}
	else {
	  window.location.assign("./../Tests/controller/sendToPhysicianSampleID.php?idList=" + getCheckedValues());	
	}  
}


The alert I created at the last minute, considering that when pressing the button without selecting any of the options, some people could get lost, not knowing if the data was sent or not.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900