SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Oct 2011
    Location
    Atlanta
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using jQuery to look up City and State from Zip Code entry

    Hi.

    We have been working on a multi-step form that collects user's zip code in step-1, and returns city and state in step-4. And finally got it working!

    But, then, as I was trying to finagle some other usability, the functionality has stopped working.

    Form elements and javascript code snippets:

    Code HTML4Strict:
                                  ...
                                  ...
    			    <label>Zip Code:</label>
    				<input type="text" id="searchzipcode" name="SearchZipCode" value="Zip Code" class="required" title="Please enter your Zip Code here." />
                                  ...
                                  ...
                                  ...
    			    <label class="small_left_c">City:</label>
    				<input type="text" id="city" name="city" value="City" class="required" title="Please enter your City here." />
    			    <label class="small_right_s">State:</label>
    				<input type="text" id="state" name="state" value="State" class="required" title="Please enter your State here." />
                                  ...
                                  ...
    Code JavaScript:
    <script type="text/javascript">
    jQuery(document).ready(function($) {       
    	var current_step = 1;
    	$('form#home_form').submit(function(e) {
     
    		var isValidZip = /(^\d{5}$)|(^\d{5}-\d{4}$)/.test(jQuery('#searchzipcode').val());
    		if(current_step == 1){
    			if(!isValidZip){
    				alert('Please enter a valid Zip Code.');
            	}
            	else{
    				$('#home_form fieldset').hide();
    				$('#step-2').show();
    				current_step++;
    				jQuery.getJSON('/zip-lookup.php?zip='+jQuery('#searchzipcode').val(), function(data) {
    					jQuery('#city').val(data.city);
    					jQuery('#state').val(data.state);
    				});
    ...
    ...



    I had changed the id of both city and state to id="v_city" & id="v_state" (in the form only) when I noticed the error. So I reverted it immediately.

    However, the error remains.

    I have been reading line by line for hours now, and can't find any difference from the file and the backup I made prior to making changes.

    I even copied the backup files back into the folder, but get the error still!


    Any ideas??


    (I can provide the entire code, or link to it, if needed.)


    Thanks, in advance!

  2. #2
    SitePoint Member
    Join Date
    Oct 2011
    Location
    Atlanta
    Posts
    16
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, after a hard reset, things are back to normal. (maybe a cache issue, or session variables.)

    While the problem is fixed, I would still appreciate any insight as to the "Why" for this problem.

    Cheers!
    Last edited by A+Consulting; Apr 5, 2012 at 06:34. Reason: (early morning typos)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •