SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Google Zombie ssandecki's Avatar
    Join Date
    Aug 2007
    Location
    Chicago, IL
    Posts
    665
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript to submit zipcode to google maps (was "Help with something simple...")

    I have a simple question and hopefully someone can be kind enough to help . I need to make a simple javascript script\form to do the following....

    1. Allow some to enter their zipcode in the text field & hit submit.

    2. This will then open a new browser page with the following URL below...

    http://www.google.com/maps?f=q&hl=en...=self+storage+ZIPCODEHERE&ie=UTF8&z=12&om=1

    The bolded text is where the zipcode should of been inserted. The entire URL must stay intact, I just need this simple thing and my lack of javascript knowledge really makes it awful, hopefully someone can help. I'd like to give thanks very much to whoever decides to help me with this!

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Code HTML4Strict:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <html>
    <head>
    <title>Google Maps</title>
    <script type="text/javascript">
    function getMap (frm) {
    	var target = "http://www.google.com/maps?f=q&hl=en&geocode=&q=self+storage+";
    	var ending = "&ie=UTF8&z=12&om=1";
    	var zipcode = frm.elements['zipcode'].value;
    	if (zipcode.length > 0) { // data entered
    		window.location.href = target + zipcode + ending;
    		return false;
    	}
    	return false;
    }
    </script>
    </head>
     
    <body>
    <form onsubmit="return getMap (this)">
    <input type="text" name="zipcode" /><br />
    <input type="submit" name="submit" value="SUBMIT" />
    </form>
    </body>
    </html>
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    what about people who have javascript turned off? should the form work for them too? or should they get an error message?
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


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
  •