PHP 文件和 Javascript 函数不捕获 Html div id 以在单击提交按钮后显示隐藏的 div

PHP file and Javascript function doesn't capture Html div id to show hidden div after clicking submit button

我在 index.php

中有这个 div
 <div class="class" id="ScoreResult" style="display:none;">

我在 seosystem/controller/youtubedata.php 中有这个功能我尝试使用 Js 它没有用所以我想当用户提交按钮时它显示 div 来显示数据

if($_SERVER['REQUEST_METHOD'] == "GET" && isset($_GET['url'])  && isset($_GET['submit'])){

        /*  echo  "</br >" ; 
        echo   $input_Url_data   .  "Button clicked" ;  */    
        $id_position = strstr($input_Url_data,"=");
        $id_position = trim($id_position, "=" );
         // the alert works normally
        echo '<script> alert("heelo"); </script>';

        // this part that trying to show the div doesn't work
        echo '<script type="text/JavaScript">
        function showtable1()
        {
         
         document.getElementById( "ScoreResult").style.display = "block";
     
            
         }
                showtable1(); 
            </script>'
        ;
            
        echo "<style type=\"text/css\"> #ScoreResult {display:block;}</style>";
      }
            
        

  

这是输入和按钮的形式,我不确定我应该执行 index.php 还是 seosystem/controller/youtubedata.php

<form class="d-flex justify-content-center " method="GET" action="index.php">
  <div class="input-group ">
    <input type="text" class="form-control" name="url" placeholder="Enter Youtube Video URL" aria-label="Example text with button addon" aria-describedby="button-addon1">
    <input class="btn" value="Analyze" name="submit" type="submit" id="button-addon1"></input>
  </div>
</form>

将此代码添加到您的 index.php 文件中。这就是您有选择地显示和隐藏 ScoreResult div 的方式。希望对你有用。

<?php
// This part should be added to the php section at the top of the page

// Start by setting the $url_set status to 0
$url_set = 0;
if (isset($_GET['url'])) {
    // Now we set the $url_set status to 1
    $url_set = 1;
}

?>

<div class="class" id="ScoreResult"></div>
<!--This section links the $url_set status to the code-->
<input type="hidden" value="<?php echo $url_set ?>" id="url-status">

<!--Replace your JS section with this-->
<script>
function showtable1() {
    const
        url_status = document.querySelector('#url-status').value,
        dsp_status = url_status == 1 ? 'block' : 'none'

    document.getElementById("ScoreResult").style.display = dsp_status;
}

showtable1();
</script>