我是JavaScript新手,我一直在做一些工作,在HTML和JavaScript中創建表單。在這項工作中,我一直試圖根據輸入到前一個字段的文本限制字段的字符串。輸入的數據改變了字符串長度
什麼,我一直在嘗試是如果該國「澳大利亞」被輸入到比「郵編」文本框「國家」文本框中僅限於4個數字(澳大利亞郵編標準)
我有做了這麼多,到目前爲止函數:
document.getElementById('txtcountry').onblur = function postcode()
{
var country = document.getElementById('txtcountry').value;
if (country == "Australia" || category == "australia")
{
document.getElementById('txtpostcode').maxLength = 4;
}
else
{
document.getElementById('txtpostcode').maxLength = 9;
}
}
這裏是我使用的功能與初始HTML的段:
<b>Postcode:</b> <input type="text" id="txtpostcode" name="postcode">
<br>
<b>Country:</b> <input type="text" id="txtcountry" name="country">
我打電話ŧ他的功能使用:
<form name="rego" action="submit.htm" onsubmit="return !!(validateText() & validateCheckBoxes(this) & validateRadioButton() & validateEmail() & populateInstitution() & postcode());" method="POST">
任何幫助真的會很感激!
UPDATE:我有我的功能更新一些幫助後,要完成的功能,因爲它似乎並沒有工作,我需要它的一些進一步的幫助
最大長度正是我一直在尋找除了一些原因,當我完成它似乎沒有工作 – bigsenator 2013-04-05 09:16:37
見我的編輯功能。當然,您確實需要實際調用該函數。這是一個工作示例:http://jsfiddle.net/nnnnnn/hk6bE/ – nnnnnn 2013-04-05 09:17:59
嗯仍然似乎沒有爲我工作:/ – bigsenator 2013-04-05 09:30:07