How to concatenate vars for this code

Discussion in 'JavaScript' started by suspicion, Apr 26, 2010.

  1. #1
    I have the following code:
    Event.observe($('store_locator_form'), 'submit', function() {
            $('storelocator-results').style.visibility = 'visible';
            storeLocator.search($('address').value, {
                radius: $('radius').value
            });
        });
    Code (markup):
    This is for a store locator script. I have it currently running off one field called "address" I need to add fields to the form and change the current address field to "city" and add "state" and "zip"
    How do I concatenate the fields city, state and zip into address? I have to put it all into one because the address is all in one field in the db and address is also being run through a script for googlemaps. I have tried many ways and have been unsuccessful.

    Thanks for any help!
     
    Last edited: Apr 26, 2010
    suspicion, Apr 26, 2010 IP
  2. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #2
    you are using Prototype right? you can do it maybe like this: $('city').value + "someseparator" + $('state').value + "someseparator" + $('zip').value :D
     
    gapz101, Apr 27, 2010 IP
  3. suspicion

    suspicion Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3

    Yes it is prototype.

    That is a possible solution but how do I attach it to be the var address?

    Thanks!
     
    suspicion, Apr 27, 2010 IP
  4. gapz101

    gapz101 Well-Known Member

    Messages:
    524
    Likes Received:
    8
    Best Answers:
    2
    Trophy Points:
    150
    #4
    try this, this may not be the correct solution :D
     
    gapz101, Apr 27, 2010 IP
  5. suspicion

    suspicion Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    SWEET! Thank you.

    It worked no problem. I had the var part but wasn't getting this:
    storeLocator.search(finalAddress, {
    Code (markup):
     
    suspicion, Apr 28, 2010 IP