javascript - Data entered alters string length -
i new javascript , have been doing work creating form in html , javascript. in work have been trying limit string of field depending on text entered previous field.
what have been trying if country 'australia' entered 'country' text box 'postcode' text box limited 4 numbers (the australian postcode standard)
i have done of function far:
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; } } here segment of initial html have use function with:
<b>postcode:</b> <input type="text" id="txtpostcode" name="postcode"> <br> <b>country:</b> <input type="text" id="txtcountry" name="country"> i calling function using :
<form name="rego" action="submit.htm" onsubmit="return !!(validatetext() & validatecheckboxes(this) & validateradiobutton() & validateemail() & populateinstitution() & postcode());" method="post"> any appreciated!
update: have updated function finished function after doesn't seem work , need further it
are trying set maxlength property:
var pc = document.getelementbyid('txtpostcode'); pc.maxlength = 4; pc.value = pc.value.substr(0,4); // remove characters entered ...and add else condition set maxlength whatever default other countries.
you call postcode() function blur event of txtcountry field.
edit: note function you've shown has undefined variable category in second part of if test - should country. , mentioned need call function somewhere.
Comments
Post a Comment