Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Spaces in variables

    I can't seem to get by this simple problem.
    If selected_city is Gila Bend -- it only shows Gila.
    I am missing something basic.


    function requestCustomerInfo() {
    var Id = $("#selected_city").val();
    alert(Id);
    $("div#divCustomerInfo").load("GetCustomerData.php?id=" + Id);
    }
    Last edited by Lonestar Jack; 09-12-2012 at 05:23 PM. Reason: misspelling

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,391
    Thanks
    11
    Thanked 568 Times in 561 Posts
    You should look at your HTML code ... the selected text might be "Gila Bend", but .val() will get the value property from the option, which might be different from the visible text

    Example
    Code:
    <select id="selected_city">
       <option value="Gila">Gila Bend</option>
    </select>
    If your option value is OK, you should always encode parameters that you want to transfer via a URL using the encodeURIComponent() method
    Code:
    $("div#divCustomerInfo").load("GetCustomerData.php?id=" + encodeURIComponent(Id))
    Last edited by devnull69; 09-12-2012 at 09:53 PM.

  • #3
    New to the CF scene
    Join Date
    Nov 2009
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    devnull69
    Thanks - I forgot about the urlencode urldecode functions.
    Works perfect


  •  

    Posting Permissions

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