初心者の質問です。私は現在 JS を学んでおり、単純な html フォームからテキスト入力を取得する関数を作成しようとしています。テキスト入力を関数に渡す方法がわかりません。これは私が現在試していることです:
<html>
<body>
<script type = "text/javascript">
<!--
var myColor = document.getElementById("textbox").value;
function findColor(){
switch(myColor){
case "Blue":
document.write("just like the sky!");
break
case "Red":
document.write("Just like wine!");
break
default:
document.write("Suit yourself then...");
}
}
//-->
</script>
<form>
Colour <input type="text" name="inputform" id="textbox" value="">
<input type="submit" value="Submit" onclick="findColor();">
</form>
</body>
</html>
ありがとう、助けていただければ幸いです。