How can we call Php functions based on the Java script If-else condition?

Active3 hr before
Viewed126 times

6 Answers


Meta Stack Overflow , Stack Overflow Public questions & answers , About ,Thanks for contributing an answer to Stack Overflow!

However with PHP you can render HTML and JavaScript code such that it is only rendered when your PHP condition is true. Maybe you may want to try something like this:

if($value == 1) {
   echo "<script>";
   echo "alert('This is an alert from JavaScript!');";
   echo "</script>";
load more v

Conditional statements are used to perform different actions based on different conditions.,Very often when you write code, you want to perform different actions for different conditions. You can use conditional statements in your code to do this.,In PHP we have the following conditional statements:,if...elseif...else statement - executes different codes for more than two conditions

$a = 50;
$b = 10; >
   echo "Hello World";

// The most basic method
echo '<script type="text/javascript">',
     'someJsFunc();', // Or Whatever

// However, if what you are trying to achieve requires more complexity,
// You might be better off adding the V8JS module, see link below
load more v

The if construct is one of the most important features of many languages, PHP included. It allows for conditional execution of code fragments. PHP features an if structure that is similar to that of C: , If statements can be nested infinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your program. , As described in the section about expressions, expression is evaluated to its Boolean value. If expression evaluates to true, PHP will execute statement, and if it evaluates to false - it'll ignore it. More information about what values evaluate to false can be found in the 'Converting to boolean' section. , Often you'd want to have more than one statement to be executed conditionally. Of course, there's no need to wrap each statement with an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if $a is bigger than $b, and would then assign the value of $a into $b:

if (expr)

PHP code won't actually call the function for you. It just prints whatever is in the echo statement to the page, it doesn't trigger any function names it prints.,I need to call the function in a php code, on condition Heres my code:,Write the same if statement again in the place you want the second text box. As …, If you don't mind my asking, why disable the textboxes? Instead, you can have PHP print them out, or not print them out:

I have a javascript function to disable and enable a textbox.

function enable()

function disable()

I need to call the function in a php code, on condition
Heres my code:

$cc = $row['company_country'];
$s = "SG";
if ($cc == $s)
echo "<SCRIPT LANGUAGE='javascript'>disable()</SCRIPT>";
//echo "test ";
echo "<SCRIPT LANGUAGE='javascript'>enable()</SCRIPT>";
load more v

Where do I find functions?,Inheritance in JavaScript,Setting up your own test automation environment,Asynchronous JavaScript overview

let myText = 'I am a string';
let newString = myText.replace('string', 'sausage');
// the replace() string function takes a source string,
// and a target string and replaces the source string,
// with the target string, and returns the newly formed string
load more v

Other "functions-undefined" queries related to "How can we call Php functions based on the Java script If-else condition?"