JavaScript How to call js function from php? call function from another python file,call function from another

I have a php page, a html button on it and there I should call a JS function with a php variable. And I get the error

the variable is not defined

Here is the code:

<body>
    <form  class="form">
    <?php
    if(file_exists('megjelenitendo.txt')){
        $mappak=array();
        $mappakdb=0;
        $megjelenitendo = fopen("megjelenitendo.txt", "r") or die("Unable to open file!");
        while(!feof($megjelenitendo)) {
             $mappak[$mappakdb]=fgets($megjelenitendo) ;
             $mappakdb++;
            }   
        fclose($megjelenitendo);
        $j=0;

        foreach(glob('*') as $filename){
            for($i=0; $i<$mappakdb;++$i){
            //echo $filename."==".$mappak[$i];echo "<br>";
            if(strtoupper($filename)==strtoupper(trim($mappak[$i]))){
             //echo '<button type="submit" id='.$i.' class="button" formaction='.$filename.' />'.$filename;//substr($filename, 3,strlen($filename));
            echo '<button type="button" id='.$i.' class="button" OnClick=mappanyitas('.trim($mappak[$i]).')>'.trim($filename).'</button>';
             echo '<br>';         
         }
             else{} 
         }
     }}

     else{
        echo "A mappa elemei:<br>";
     }
    ?>
    </form>

    <script type="text/javascript">
         function mappanyitas(filename){
            alert(filename);
        }

    </script>
</body>
Answer:1

You can call javascript function like this :

<?php 
    echo "<script>functionName();</script>";
?>

But function should be defined already.

Answer:2
echo '<button type="button" id='.$i.' class="button" OnClick=mappanyitas("'.trim($mappak[$i]).'")>'.trim($filename).'</button>';
Answer:3

try this line

echo '<button type="button" id='.$i.' class="button" onclick="mappanyitas('.trim($mappak[$i]).')">'.trim($filename).'</button>'

Let me know if this solved your problem!

P.S. Check the rendered page's HTML and check the button's code, to check if the variable's value was successfully injected into the code

Answer:4

Most of Node.js top modules I inspect always define their regexp in the module scope, outside the function using it. For example, few lines taken from Busboy, the fastest multipart/form-data parser ...

Most of Node.js top modules I inspect always define their regexp in the module scope, outside the function using it. For example, few lines taken from Busboy, the fastest multipart/form-data parser ...

  1. javascript node regex
  2. node js regexp
  3. node js regexp match
  4. node js regexp exec
  5. node js regexp replace
  6. node js regexp escape
  7. js node regex
  8. node js regex match
  9. node js regex replace
  10. node js regex test
  11. node js regex named capture group
  12. node js regex match example
  13. node js regex capture groups
  14. node js regex example
  15. node js regex match all
  16. node js regex match group
  17. node js regex online
  18. node js regex tester
  19. node js regex group
  20. node js regex special characters

I have an array which represents the points of a graph with different values like the following one: var array = [5, 3, 4, 1, 2]; I would like to loop through it and create a new array where the new ...

I have an array which represents the points of a graph with different values like the following one: var array = [5, 3, 4, 1, 2]; I would like to loop through it and create a new array where the new ...

  1. make average values

I want to create a year selection dropdown. year must start from this year upto next 7 years . I have tried var year = new Date().getFullYear(); var range = []; range.push(year); for (var i = 1; i ...

I want to create a year selection dropdown. year must start from this year upto next 7 years . I have tried var year = new Date().getFullYear(); var range = []; range.push(year); for (var i = 1; i ...

  1. angular create dynamic component
  2. angular create dynamic forms
  3. angular create dynamic module
  4. angular create dynamic table
  5. angular create dynamic object
  6. angular create dynamic array
  7. angular create dynamic year dropdown
  8. angular create dynamic id
  9. angular create dynamic css class
  10. angular create dynamic templateref
  11. angular create dynamic link
  12. angular create dynamic class
  13. angular create dynamic variable
  14. angular create dynamic form group
  15. angular create dynamic template variable
  16. angular create dynamic variable name
  17. angular create dynamic html
  18. angular create dynamic menu
  19. angular create dynamic template
  20. angular create dynamic element

I cannot seem to get the timeout and the loop to work together. If I remove the loop it works or if I remove the timeout it will work. Together I will get an infinit loop and it doesnt seem like the ...

I cannot seem to get the timeout and the loop to work together. If I remove the loop it works or if I remove the timeout it will work. Together I will get an infinit loop and it doesnt seem like the ...