<head>
<script language='javascript' type='text/javascript'>
function insertTemplate() {
console.log('something is coming out');
if (document.getElementById('template').checked) {
var test = "lore ipsum";
document.getElementById('message') = test;
alert(test);
}
else (
var nothing = '';
document.getElementById('message') = nothing;
)
}
</script>
</head>
<body>
<form class='form-horizontal' role='form' method='post'>
{{ csrf_field() }}
<input type='text' name='address'><br>
<input type='text' name='subject'><br>
<input type='checkbox' name='template' id='template' onclick = "insertTemplate()"> Insert in template</br>
<input type='text' name='message' id = 'message' style='width:500px;height:500px;'><br>
<button type='submit'>Submit</button>
</form>
</body>
答案 0 :(得分:1)
您的else
块由括号而不是花括号分隔。
<form class='form-horizontal' role='form' method='post'>
{{ csrf_field() }}
<input type='text' name='address'><br>
<input type='text' name='subject'><br>
<input type='checkbox' name='template' id='template' onclick = "insertTemplate()"> Insert in template<br>
<input type='text' name='message' id = 'message' style='width:500px;height:500px;'><br>
<button type='submit'>Submit</button>
</form>
<script>
function insertTemplate() {
console.log('something is coming out');
var test = "lore ipsum"
var nothing = "";
if (document.getElementById('template').checked) {
document.getElementById('message').textContent = test;
alert(test);
} else {
document.getElementById('message').textContent = nothing;
}
}
</script>