不工作的代码Javascript内echo在PHP中


Doesn’t work the code Javascript inside echo in PHP

我已经尝试了很多次来解决这个问题,当选项"OTROS"被选中时,它必须显示div#contenedoropots,但它不工作的脚本里面的echo PHP。

PHP

<option id="copiado"
  <?php 
    if($columna['tipo_defecto'] == "OTROS"){                            
        echo 'selected ';
        echo "<script type='text/javascript'>";
        echo "document.getElementById('contenedoropots').style.display = 'block';";
        echo "</script>";                                   
    } 
?>                  
        >OTROS</option>

<div id="contenedoropots" style="display:none">
     <label id="labelcopiarA" for="cpOtros">Especificar:</label>
     <input id="copiar" type="text" name="cpOtros"  onkeyup="copiarValue();" value="<?=$columna['especificar']?>"/>
</div>

这个代码的结果在下拉列表中:

document.getElementById('contenedoropots').style.display = 'block';>OTROS

如何让脚本工作在echo PHP

当前输出产生无效的html标签,尝试在关闭任何打开的option-element之后添加javascript,甚至在关闭select-element之后添加更好。

<option id="copiado" <?php 
    if($columna['tipo_defecto'] == "OTROS"){                            
        echo 'selected="selected"';
    } 
?>>OTROS</option>
<!-- complete the html-elements (options, select), then output the javascript if needed -->
<?php
    if($columna['tipo_defecto'] == "OTROS"){                            
        echo "<script type='text/javascript'>";
        echo "document.getElementById('contenedoropots').style.display = 'block';";
        echo "</script>";                                   
    } 
?>