2017-01-19 6 views
-1

私のコードに少し問題があります。私はトンが達成しようとしていても何のidはnullPHPを使ってCSSからIDを取得する

<!DOCTYPE html> 
 

 
<?php 
 

 
if (isset($_POST["get_name"])) { 
 
    
 
    $theName = $_POST["my_name"]; 
 
    echo "<script> 
 
document.getElementById('text').style.display = 'block'; 
 
document.getElementById('name').style.display = 'none'; 
 

 
</script>"; 
 
} 
 
?> 
 

 
<html> 
 
<head> 
 
<style> 
 

 
#check { 
 
     background-color: yellow; 
 
     color: black; 
 
     border-color: yellow; 
 
     border-radius: 15px; 
 
     display: inline-block 
 
} 
 

 
#text { 
 
display: none; 
 
} 
 

 
#name { 
 

 
} 
 

 
</style> 
 
</head> 
 
<body> 
 

 
<form id="name" action="" method="post"> 
 
Name: <input type="text" name="my_name" placeholder="Your name here" required> 
 
<input type="submit" name="get_name" value="Enter"> 
 
</form> 
 

 
<form id="text" action="" method="post"> 
 
Your text: <textarea name="getText" row="10" col="10"></textarea> 
 
<input type="submit" name="get_text" value="Enter"> 
 
</form> 
 

 
</body> 
 
</html>

がないと言って、私はPHPの内部ではJavaScriptを使用して、ページのスタイルを変更するようなCSSの内容の一部を変更したいということですが、私はエラーを持っています
+1

? –

+0

コードを更新する –

+0

'style'タグに' script'タグを使っていると思います!! –

答えて

1

あなたはheadscriptタグを入れる必要があります。

`ID = "テキスト"`を持つフィールドがある
<!DOCTYPE html> 

<html> 
<head> 


<?php 

if (isset($_POST["get_name"])) { 

    $theName = $_POST["my_name"]; ?> 

<script> 
document.getElementById('text').style.display = 'block'; 
document.getElementById('name').style.display = 'none'; 

</script> 

<?php 
} 
?> 


<style> 

#check { 
     background-color: yellow; 
     color: black; 
     border-color: yellow; 
     border-radius: 15px; 
     display: inline-block 
} 

#text { 
display: none; 
} 

#name { 

} 

</style> 
</head> 
<body> 

<form action="" method="post"> 
Name: <input type="text" name="my_name" placeholder="Your name here" required> 
<input type="submit" name="get_name" value="Enter"> 
</form> 

<form id="text" action="" method="post"> 
Your text: <textarea name="getText" row="10" col="10"></textarea> 
<input type="submit" name="get_text" value="Enter"> 
</form> 

</body> 
</html> 
+0

私はそれを頭に入れました –

+0

@cleomaster I 'php'セクションを変更しました。試してみてください –

+0

私はそれを修正しました。私はちょうどボディセクションにPHPコードを入れなければなりませんでした。 –

関連する問題