Jump to content

Recommended Posts

<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 by thehubclick
missed something

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.

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 by thehubclick
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 by thehubclick
typo
  • 5 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.