[英]document.getElementById(“”) = “” does not work in Laravel blade
我正在尋找一種在表單中設置“值”的方法,我試過這個,但它不起作用。 我該如何解決?
錯誤說
未捕獲的 ReferenceError:setData 未在 HTMLInputElement.onclick 中定義
但是 setDate() 肯定存在....
<script>
function setData() {
document.getElementById("year").value = "2022";
}
</script>
<div>
<form method="GET" action={{ route('test')}}>
{{ Form::select('month', $date, 0 ) }}
<input type="button" id="b1" value="BUTTON1" onclick="setData()">
</form>
</div>
<form method="post" action={{ route('output')}}>
@csrf
<div class="col-md-6">
<input type="text" id="year" name="year" value ="2021">
<input type="text" name="month" value ="7"> <input type="text" name="day" value ="1">
</div>
</form>
嘗試使用以下腳本,
將名稱添加到您的第二個表單
<form method="GET" action="{{ route('test')}}">
<select name="" id="month">
<option value="">Select</option>
<option value="jan">Jan</option>
<option value="feb">Feb</option>
</select>
<input type="button" id="b1" value="BUTTON1" onclick="setData()">
</form>
<form method="post" id="form2" action="{{ route('output')}}">
@csrf
<div class="col-md-6">
<input type="text" id="year" name="year" value ="2021">
<input type="text" name="month" value ="7"> <input type="text" name="day" value ="1">
</div>
</form>
<script>
var secondForm = document.getElementById('form2');
function setData() {
secondForm.year.value = '2022';
}
</script>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.