thehubclick Posted December 1, 2019 Share Posted December 1, 2019 (edited) <script type="text/javascript"> function checker1() { (tboxinp1.value==000) { alert("error3") } { // call php script from javascript ??? <?php not looking to use alert here is part of the php script to call } <?php /// can I put a function to call this. This php script is taken from my sumbit button. I want to check if condition mets before the submit sends the data $t = $_GET["email"]; echo '<script>checker1()</script>'; if ($t == 1) { // heres submit i want to call from javascript if(isset($_POST['textdata'])) i dont know how to approach this javascript call. Thanks if you can help. What i mean is the <?php script runs when i click submit i want to catch if data was not entered before it submits, if it does not i like the submit to cancel. The php script as follows when submit button is clicked <?php $t = $_GET["email"]; echo '<script>checker1()</script>'; if ($t == 1) { if(isset($_POST['textdata'])) { // return false; session_start(); $cm_name = $_GET["name"]; // Check if a text file exists. // If not create one and initialize it to zero. if (!file_exists($cm_name)) { - $f = fopen($cm_name, "w"); - fwrite($f,"0"); - fclose($f); } // Read the current value of our counter file $f = fopen($cm_name,"r"); $cmVal = fread($f, filesize($cm_name)); fclose($f); // Has visitor been counted in this session? // If not, increase counter value by one if(!isset($_SESSION['hasVisited'])){ - $_SESSION['hasVisited']="yes"; - $cmVal++; - $f = fopen($cm_name, "w"); - fwrite($f, $cmVal); - fclose($f); echo "Have a good day!"; } echo '<script>showname()</script>'; // $data=$_POST['textdata']; // $fp = fopen('data1.txt', 'a'); // fwrite($fp, $data); // fclose($fp); } //echo "Have a good day!"; } // echo '...'; ?>d Edited December 1, 2019 by thehubclick missed something Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/ Share on other sites More sharing options...
gw1500se Posted December 1, 2019 Share Posted December 1, 2019 First please use the code icon (<>) to embed it in a post and choose the correct code format. It makes your code much easier to read. Second, there are several ways to accomplish what you want. Probably the most common way is to include the javascript in the PHP page you want executed. Run the javascript and return true or false then test that in the PHP code to determine if the data meets the requirements to run the script. If not then output an error or something, otherwise run the code. If you really want to execute a PHP script from javascript then you need to use Ajax. Just search for "PHP Ajax" and you will find plenty of references with examples. Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572063 Share on other sites More sharing options...
thehubclick Posted December 1, 2019 Author Share Posted December 1, 2019 (edited) Sorry Not sure how to Use <> my code inside (< <script type="text/javascript"> function sam_click() { var x="<?php ex(); ?>"; alert(x); return false; } </script> >) I cant find the edit to fix my code. So did this test. Ty Edited December 1, 2019 by thehubclick Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572065 Share on other sites More sharing options...
thehubclick Posted December 1, 2019 Author Share Posted December 1, 2019 (edited) 1 hour ago, gw1500se said: First please use the code icon (<>) to embed it in a post and choose the correct code format. It makes your code much easier to read. Second, there are several ways to accomplish what you want. Probably the most common way is to include the javascript in the PHP page you want executed. Run the javascript and return true or false then test that in the PHP code to determine if the data meets the requirements to run the script. If not then output an error or something, otherwise run the code. If you really want to execute a PHP script from javascript then you need to use Ajax. Just search for "PHP Ajax" and you will find plenty of references with examples. Ok ty. I cant get my test <> To work how do i learn on this forum how to embed Is it (< my code. >) Let me know because in my test i did < my code > But it didnt work. Ty Edited December 1, 2019 by thehubclick typo Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572066 Share on other sites More sharing options...
Barand Posted December 1, 2019 Share Posted December 1, 2019 3 hours ago, gw1500se said: the code icon (<>) Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572068 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 On 12/1/2019 at 1:16 PM, Barand said: The reason i dont see it is because im on my phone. I code on my phone. Not the desktop. Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572996 Share on other sites More sharing options...
Barand Posted December 31, 2019 Share Posted December 31, 2019 It does disappear with narrow display sizes. Try shrinking your display (zoom out/ Ctrl-minus) Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572998 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 It might be my Firefox browser. Look at screenshot my screen wont zoom. Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1572999 Share on other sites More sharing options...
Barand Posted December 31, 2019 Share Posted December 31, 2019 What if you rotate to landscape? Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573000 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 Im on my phone Barand? Ctrl + - is done on Desktop. I dont use my desktop much. Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573001 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 1 minute ago, Barand said: What if you rotate to landscape? Il try landacape Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573002 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 4 minutes ago, thehubclick said: Il try landacape Heres landscape screenshot Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573003 Share on other sites More sharing options...
Barand Posted December 31, 2019 Share Posted December 31, 2019 I have no such problems with my phone 1 Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573004 Share on other sites More sharing options...
thehubclick Posted December 31, 2019 Author Share Posted December 31, 2019 (edited) 1 minute ago, thehubclick said: Heres landscape screenshot I dont see <> lol i need sleep Edited December 31, 2019 by thehubclick Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573005 Share on other sites More sharing options...
Barand Posted December 31, 2019 Share Posted December 31, 2019 I guess the designers of the forum software thought emojis were far more important Quote Link to comment https://forums.phpfreaks.com/topic/309605-need-to-call-my-php-script-from-javascript/#findComment-1573007 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.