當我在表單域中輸入時,底部的輸入也應該自動寫入與上述域相同的地址。TypeError:ID不是函數
我使用的JavaScript正在工作,當我有外面的輸入,你可以看到下面,但我需要它的形式提交。我在控制檯得到的錯誤是「類型錯誤:自動地址是不是一個函數」下表的工作方式
<form id="addNews" name="address" action="addevent.php" method="post" class="addStuff" enctype="multipart/form-data">
<h3>Address1:</h3><input type="text" class="title" name="address1" onkeyup="autoAddress();">
<h3>Address2:</h3><input type="text" class="title" name="address2" onkeyup="autoAddress();">
<h3>City:</h3><input type="text" class="title" name="city" onkeyup="autoAddress();">
<h3>County:</h3><input type="text" class="title" name="county" onkeyup="autoAddress();">
<h3>PostCode:</h3><input type="text" class="title" name="pcode" onkeyup="autoAddress();">
</form>
<input type="text" name="fulladdress" class="title" id="autoAddress" />
我需要什麼行不通,並在下面。我確定我只是缺少一些簡單的東西。注意底部的輸入位於表單內部。
<form id="addNews" name="address" action="addevent.php" method="post" class="addStuff" enctype="multipart/form-data">
<h3>Address1:</h3><input type="text" class="title" name="address1" onkeyup="autoAddress();">
<h3>Address2:</h3><input type="text" class="title" name="address2" onkeyup="autoAddress();">
<h3>City:</h3><input type="text" class="title" name="city" onkeyup="autoAddress();">
<h3>County:</h3><input type="text" class="title" name="county" onkeyup="autoAddress();">
<h3>PostCode:</h3><input type="text" class="title" name="pcode" onkeyup="autoAddress();">
<input type="text" name="fulladdress" class="title" id="autoAddress" />
</form>
的JavaScript是如下
function autoAddress(){
var address1 = document.address.address1.value;
var address2 = document.address.address2.value;
var city = document.address.city.value;
var county = document.address.county.value;
var postcode = document.address.pcode.value;
var parts = [
address1,
address2,
city,
county,
postcode
];
var address = new Array();
for (var i=0; i<=parts.length; i++){
if (parts[i]){
address.push(parts[i]) ;
}
}
var joined = address.join(', ');
document.getElementById('autoAddress').value = joined;
}
「不起作用」是什麼意思? –
確定其他所有東西都一樣嗎? – benestar
當我在表單域中輸入時,底部的輸入也應該自動寫入與上述字段相同的地址。 –