SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot ozonew4m's Avatar
    Join Date
    Apr 2006
    Location
    at my desk
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    drop down ajax state

    hello everybody...

    i have a standard dropdown menu containing all the us states..

    what i want to do is when somebody selects a state i want to change the contents of a div element further down the page

    the div i want to change is called map

    heres what i have:

    the standard select box with javascript call

    Code:
    <select id="state" onchange='check_state()'name="state" size="1" tabindex="1">
                        <option value="">-- Please select --</option>
                        <option value="Alabama">Alabama</option>
                        <option value="Alaska">Alaska</option>
                        <option value="American Samoa">American Samoa</option>
                        <option value="Arizona">Arizona</option>
                        <option value="Arkansas">Arkansas</option>
                        <option value="California">California</option>
                        <option value="Colorado">Colorado</option>
    .... etc
                   </select>

    heres my javascript code that i found

    Code:
    function check_state() {
    	x = document.getElementById('state');
    
    	regex=/Alabama/i;
    	if (regex.test(x.options[x.selectedIndex].innerHTML)) {
    div = document.getElementById('map');
    div.innerHTML = 'Alabama';
    
    	regex=/Alaska/i;
    	if (regex.test(x.options[x.selectedIndex].innerHTML)) {
    div = document.getElementById('map');
    div.innerHTML = 'Alaska;
    
    
    etc....

    am i going about this the wrong way...

    what i want is if somebody selects Alabama the contents of the div map changes to Alabama

    if alaska it changes to alaska and so on for all states

    can somebody please point me in the right direction

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Looks ok, not sure why you are using regex, why not just
    Code:
    function check_state() {
    x = document.getElementById('state');
    div = document.getElementById('map');
    div.innerHTML = x.value;
    }


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
  •