yogibear Posted September 26, 2008 Share Posted September 26, 2008 Hi At the moment I have a textbox for a post code text box that when the user clicks submit, if the input doesn’t contain a space and alert is displayed saying post code must contain a space. How can I change it so that it adds a space after the 2nd character? I know this isn’t perfect but it will prevent errors on the next page (not controlled by me) saying the post code must contain a space (the postcode is not displayed to user). Thanks in advanced Best wishes Yogi Quote Link to comment Share on other sites More sharing options...
rarebit Posted September 26, 2008 Share Posted September 26, 2008 What country postcode are you working on? If it's UK, then it might be third character (can't rem if theres possibility of 4). Any which way though... if, if, if document.write(pc.substring(0, 3) + " " + pc.substring(4, pc.length)); this might need a slight tweet since it's not tested... Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted September 26, 2008 Share Posted September 26, 2008 I would suggest, that if their are two parts to the post code that you supply two text fields. But at the end of the form have a hidden form input which will be for the normal postcode. Then you can do something like this: <script language="javascript"> function set_post_code(){ document.getElementById("postcode").value = document.getElementById("postcode_one").value + " " + document.getElementById("postcode_two").value; } </script> Then in your submit button: <input type="submit" name="submit" id="submit" value="Send" onclick="javascript: set_post_code()" /> That way you can also sat max lengths on the post code boxes and check with javascript too see that they are the appropriate length. Just a suggestion, there are many ways you could go about this. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 27, 2008 Share Posted September 27, 2008 What country postcode are you working on? If it's UK, then it might be third character (can't rem if theres possibility of 4). I'm fairly sure the first part of a UK postcode can be 2, 3 or 4 characters. The last part, however, is always 3. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.