JavaScript - Postcode Check
I was wondering if there was a simple way of notifying a user who has entered an incorrect postcode? I have found numerous answers to this problem but i am sure there is a simpler way to do it as ones i have found have rows and rows of code.
Help is much appreciated Similar TutorialsHi all, I have a script that validates a postcode, including checking that the 4th character from the end of the postcode is a space. To save sending you back to the postcode textbox to correct the error, how can I automatically force a space at the 4th character position from the end of the postcode? ie, CM12JB is wrong. Need to change it to CM1 2JB. Any ideas? Gary Hi, basically it's a simple postcode validator. It checks to see whether the postcode is in UK format, then tells you if it isn't with an alert box, then I want it to clear the field. The input field's ID is postcode. Code: function testPostCode () { var myPostCode = document.getElementById('postcode').value; if (checkPostCode (myPostCode)) { document.getElementById('postcode').value = checkPostCode (myPostCode) } else {alert ("Please enter your Postcode correctly, this includes:\n \n * Correct Spacing - AA1 1AA \n * Correct amount of letters and numbers. \n \n Sorry if this causes any inconvenience, but it is to your benefit.")}; document.postcode.value=""; } Anyone able to help me? http://auspost.com.au/apps/postcode.html Basically I want to build the same thing. The data is freely available there as a download. I couldn't find anything existing in the jquery plugin space. Can anyone offer pointers on how to achieve it? Hi, I would like to set the postcode Code: <?php echo $pubdetails['rsPostCode]; ?> as a default value in the form field so that the map area loads up automatically for instance the link above uses postcode bn11 3rg thanks On this webpage http://www.corkdiscos.com/testimonials.html i have a like button. when a user clicks like a comment box appears. when i unlike the button the comment box disappears this is ok but when a user has already liked the facebook page and comes to my webpage the comment box does not show. so im looking for a piece of javascript to check if a user has like the button on my page and if so to show the comment box. please check my source code of the website http://www.corkdiscos.com/testimonials.html to see what i have so far. any help would be greatly appreciated Hi guys. I'm working a bunch of pre existing code on a CMS. Just after a quick fix. Doing a show/hide thing on a particular div somewhere on the page depending if a checkbox is ticked or not. Currently there is 3 checkboxes that are dynamically added through the CMS. Here's simplified version of the form: Code: <form id="simplesearch" name="simplesearch"> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="5" class="input-checkboxes" /> <input type="checkbox" onclick='showhidefield(this.value)' name="meta_data_array_search_criteria[custom_profile_type][]" value="4" class="input-checkboxes" /> </form> And here's the javascript I was playing with. Code: function showhidefield(id) { if(document.simplesearch.meta_data_array_search_criteria[custom_profile_type][''].checked) { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "visible"; } else { document.getElementById("profile_fields_wrapper_" + id).style.visibility = "hidden"; } } Problem I'm having is how do i do a check to see if those checkboxes are checked in the javascript with those name arrays? How do i separate them? 'm guessing I have to loop through them or something?Hopefully that make senses - it's late here and I'm losing the plot Any pointers would be gratefully welcomed I have a text input box that resets to blank when the user enters an alpha character, it also checks for the number 0 as it has to be greater than 0 too... when I submit the form it is blank the variable changes to blank (as I use parseInt to convert it to an integer at a later stage) What can I do to check and see if it is NaN value? (I've tried isNaN() and it did not do what I wanted it to) this code is supposed to ask the users name and say how many letters in it get 2 random numbers ask user to add them if right say Well Done! if wrong say Sorry, you are wrong. when i run this nothing comes up whats wrong? thanx Code: <script> var firstName = ""; var numLetters = 0; firstName = prompt("Hi, what's your first name?", ""); numLetters = firstName.length; alert ("Did you know there are " + numLetters + " letters in your name?"); var num1 = Math.floor(Math.random()*9) + 1; var num2 = Math.floor(Math.random()*9) + 1; var answer; var useranswer; answer = num1+num2; useranswer = promt("What is" + num1 + "+" + num2 + "?"); If (answer = useranswer) { alert("Well done!"); } else { alert("Sorry, you are wrong."); } </script> I have NO knowledge of Javascript at all but borrowed and attempted to adapt one I found. It is a Firefox bookmarklet designed to highlight in different colours both certain words or the ending "ing" on a word in a text document that has been saved as html. Basically it is a device for helping novel writers rid their manuscripts of redundant words and overuse of the 'ing" words. In works in part but doesn't pick up all "ing" endings. For someone who know what their doing I imagine it would take more than a few minutes to read and correct. Many thanks to anyone who can help. Here is the Javscript: javascript:var%20verbsRE=/(\b)(about|actually|almost|already|appear|approximately|basically|close to|even|eventually|exactly|finally|here|just|kind of|nearly|now|practically|really|seem|simply|somehow|somewhat|sort of|suddenly|then|there|truly|utterly|while|as|appear|felt|gaped|gawked|gazed|glanced|hear|heard|knew |looked|noticed|observed|peered|peeped|regarded|saw|scanned|see|seeing|seemed|smelled|stared|studied |surveyed|tasted|viewed|watched)(\b)/gi;var%20ingRE=/(\w)(ing)(\b)/gim;function%20HL(node){if(node.hasChildNodes){var%20hi_cn;for(hi_cn=0;hi_cn<node.childNodes.length; hi_cn++){HL(node.childNodes[hi_cn]);}}if(node.nodeType==3){var%20tempNodeVal=node.nodeValue;if(verbsRE.test(tempNodeVal)){tempNodeVal= tempNodeVal.replace(verbsRE,"$1<span%20style='background-color:yellow;color:black;border:1px%20solid%20black;'>$2</span>$3");tempNodeVal=tempNodeVal.replace(ingRE,"$1<span%20style='background-color:#0ff;color:black;border:1px%20solid%20black;'>$2</span>$3");newNode=document.createElement('span');newNode.innerHTML=tempNodeVal;pn=node.parentNode;pn .replaceChild(newNode,node);}}}HL(window.document.getElementsByTagName('body')[0]); This is perhaps a somewhat trivial point but it's bugged me a couple of times recently and I wondered if anyone out there had any thoughts on the matter. Essentially I have an action that can happen many times but I want to record whether it has happened at least once. I know we are talking about a trivial amount of processing and code here but is there any real difference between the following two methods: Code: myCheck: false, myRepeatedlyCalledFunction: function() { this.myCheck = true; // do some stuff } vs Code: myCheck: false, myRepeatedlyCalledFunction: function() { if(this.myCheck === false) { this.myCheck = true; } // do some stuff } thoughts? I got a page that gets created dynamically. sometimes I get images output with NO source like this Code: <img src="" id="md_1"> <img src="" id="md_2"> etc. etc. the image id are created dynamically also and always start with "0" and count up in order. I need to check everyone of those image links and when they are blank like above change the src to a default image. I have spent 8 hours on this one simple function and cannot seem to get it to work. I will call the function at the end of the page. This is the code part that fails it's if check. Code: while (n<=30) { var slot='#slot'+n; $( slot ).data({no: n, id: itemId[i], name: itemName[i], equip: itemEquip[i], lvl: itemLvl[i], bonus: itemBonus[i], rstr: itemRStr[i], rdef: itemRDef[i]}); $( slot ).draggable({ handle: slot, stack: slot, revert: "invalid", snap: "div#"+itemEquip[i], snapMode: 'inner', start: function(event, ui) { $('div#'+$(this).data('equip')).css({'border': '2px dashed #0066CC', 'background': 'rgba(255,255,255,0.2)'}) .droppable ({ drop: function(event, ui) { if (pLvl>=$('.ui-draggable-dragging').data('lvl') && pStr>=$('.ui-draggable-dragging').data('rstr')) { alert(pLvl+", "+$('.ui-draggable-dragging').data('lvl')); $('.ui-draggable-dragging').css({'display':'none'}); $('div#'+$('.ui-draggable-dragging').data('equip')).html ( "<img src='items/equipped/"+$('.ui-draggable-dragging').data('name')+$('.ui-draggable-dragging').data('id')+".png' />" ) $.ajax({type:"GET", url:"items/change.php", data:"id="+$('.ui-draggable-dragging').data('id')+"&no="+$('.ui-draggable-dragging').data('no'), cache:false, timeout:5000, error: function() { $('div.nogood').html ( "There was an error. Please inform us about it in the forum." ).css({'width':'400px','margin-left':'-200px'}); $( 'div.nogood' ).fadeIn(500, away); function away() { $( 'div.nogood' ).delay(2000).fadeOut(500); }; } }); } else { alert("HUh"); $( 'div.nogood' ).fadeIn(500, away).css({'width':'400px','margin-left':'-200px'});; $('.ui-draggable-dragging').draggable({revert: true}); if (pLvl<$('.ui-draggable-dragging').data('lvl')) { alert("Good"); } else if (pStr<$('.ui-draggable-dragging').data('rstr')) { $('div.nogood').html("Not enough strength.") } function away() { $( 'div.nogood' ).delay(1400).fadeOut(500); }; } } }); }, stop: function(event, ui) { $('div#'+$(this).data('equip')).css({'border':'none', 'background':'transparent'}).droppable("destroy"); } }); n++; i++; } This if comparison if (pLvl>=$('.ui-draggable-dragging').data('lvl') && pStr>=$('.ui-draggable-dragging').data('rstr')) somehow goes through. After the if statement I check the values with the alert but it displays 5 for pLvl and 10 for the draggables data (which are the correct numbers) so can anyone tell me why does this if statement still go through when pLvl is lower? Hello, I have never used javascript before, so this might be a very basic question. I have a script on my blog which places a stumbleupon button on the page. This is the code that calls the script: Code: <script src="http://www.stumbleupon.com/hostedbadge.php?s=5"></script> Today I went to my blog and it was taking a long time to load, it turns out because stumbleupons site is down so the script can't be accessed. A whole lot of other stuff on the page just doesn't load until it times out though, so it takes like 3 minutes for the page to load. What I want to know is can I test if the script is reachable and only call it if it is, so that if there is a 403 or 404 error it just won't even try to load it and continue loading the rest of the page?? Any help is greatly apprectiated! Thanks. i have an assignment to solve in which i have given two checkboxes one is enabled and another one is disabled n m required that if we select enable checkbox the disabled checkbox may also be selected automatically can any one help out for its coding please Thanks plz check bold part of function is not working. what is wrong with it.? Code: function onesizecheck(chk_id,siz) { alert(chk_id); if(document.getElementById('siz_check').value=='') { document.getElementById('siz_check').value=siz; }//end if if(document.getElementById('siz_check').value==siz) { document.getElementById('siz_check').value=siz; } else { alert('Multi size are not allowed.'); for(var i = 0; i < document.delet['checkbox[]'].length; i++){ var cb = document.getElementById('checkbox'); alert(cb[i].value); } } }//end function Is it possible to find out if an element is using a scroll bar for overflow? like I need to be able to change the size of something if there is any overflow.... Hi I am completely new to javascript, in fact just started loooking at it on w3 this week, anyhow thought I would do my first script. The script creates three random numbers between 1 and 10 but makes sure that they are completely different. It works, which is great as I have set out to achieve what was desired, however could somebody have a look and tell me if I have gone about it the right way. Code: <script type="text/javascript"> var one = (Math.floor(Math.random()*10+1)); document.write("1. " + one + "<br />"); do { var two = (Math.floor(Math.random()*10+1)); } while (two == one) document.write("2. " + two + "<br />"); do { var three = (Math.floor(Math.random()*10+1)); } while (three == two || three == one) document.write("3. " + three + "<br />" + "<br />"); </script> Thanks in advance. Joel I need to create some javascript code that asks a user a series of yes/no questions. Depending on how the user answers it will direct them to additional yes/no questions or simply stop with a message that they are not eligible. I need something similar to this site: http://www.kingfoundation.com/Grants...lity-Quiz.aspx Any help to develop this code would be much appreciated as I am a fairly inexperienced developer. All, I have the following checkbox code: PHP Code: echo "<input name=\"picbigid[]\" type=\"checkbox\" value=\"$pic[src_big]\">"; I then want to select all the checkboxes so I have this code: [PHP] echo "<input type=\"button\" name=\"CheckAll\" value=\"Check All\" onClick=\"checkAll(document.photos.picbigid)\"> <input type=\"button\" name=\"UnCheckAll\" value=\"Uncheck All\" onClick=\"uncheckAll(document.photos.picbigid)\">"; [PHP] My JS function is: Code: function checkAll(field) { for (i = 0; i < field.length; i++) field[i].checked = true ; } function uncheckAll(field) { for (i = 0; i < field.length; i++) field[i].checked = false ; } If I do it like this: PHP Code: echo "<input name=\"picbigid\" type=\"checkbox\" value=\"$pic[src_big]\">"; It works but I can't have it like that because the form posts to another PHP page that needs the input name as an array. Any ideas? Thanks! Dear all, The code below puts a link in mydiv when the page loads if myvar equals 1. Great till here, but if myvar changes its value and it does not equal 1 any more I have to reload the page in order not to see the link. What do I have to do to avoid that reload? what do I have to do to check myvar's value for changes constantly? Thanks in advance! Code: <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script> <script> var myvar=1; function func1() { if (myvar==1){ var putit=""; putit +="<a href='#'>Put this link</a>"; $("#mydiv").html(putit); } } function addLoadEvent(func) { $(window).load(func); } addLoadEvent(func1); </script> </head> <body> <div id="mydiv"></div> |