SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    change value of input box depending on other form fields

    basicly what im trying to do is have 4 forms fields
    1 input box for a country
    1 drop down box for states
    1 input box for city

    and 1 empty input box which add the value the other three as soon as they are changed, so it would end up looking something like this

    first writes= united states
    second selects = CA
    third writes = san diego

    and the fourths value should be

    san diego, CA , United states

    is that possible with javascript?

  2. #2
    SitePoint Wizard wonshikee's Avatar
    Join Date
    Jan 2007
    Posts
    1,223
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    It's exactly the kinda thing javascript is good for


    HTML Code:
    <script type='text/javascript'>
    function combine()
    {
        var country = document.getElementById('country').value;
        var city = document.getElementById('city').value;
        var st = document.getElementById('state');
        var state = st.options[st.selectedIndex].value;
    
        if (country && city && state) {
             document.getElementById('combined').value = city + ", " + state + " " + country;
        }
    }
    </script>
    
    Country: <input type='text' id='country' name='country' onblur='combine()' /><br />
    
    State: <select id='state' name='state' onchange='combine()'>
    <option value=''>Please Select</option>
    <option value='AK'>Arkansas</option>
    <option value='CA'>California</option>
    </select><br />
    
    City: <input type='text' name='city' id='city' onblur='combine()' />
    
    <input type='text' name='combined' id='combined' />

  3. #3
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    sweet, thanks

  4. #4
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    398
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one last thing, i hoping it be easier

    i tried to integrate that with google maps geocoder

    http://www.google.com/apis/maps/docu...ng-simple.html

    but without having to click "go". heres what i tried, but its not working

    http://ridenze.com/spots/find_spot.html

    supposably its going to be hidden, but the onchange thing doesnt seem to be working... any ideas?

    thanks a lot


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
  •