javascript drop down list for state state selection doesn't work

Discussion in 'Javascript' started by JRough, Oct 7, 2009.

  1. JRough

    JRough Guest

    Can you see what is wrong with this state field, form input? I get
    an error in php that says Unknown column 'state' in 'field list'
    which makes me think that the value isn't getting posted in the form.
    Can you let me know I did wrong or if the Javascript is right? There
    is more to the form I'm just giving you the field that doesnt' work.
    thanks,

    <label for="state">State</label>
    <select id = "state" name = "state"> onChange="this.form.getElementByID
    ("state").value=this[this.selectedIndex].value">
    <option value="AL">Alabama
    <option value="AK">Alaska
    <option value="AZ">Arizona
    <option value="AR">Arkansas
    <option value="CA">California
    <option value="CO">Colorado
    <option value="CT">Connecticut
    <option value="DE">Delaware
    <option value="FL">Florida
    <option value="GA">Georgia
    <option value="HI">Hawaii
    <option value="ID">Idaho
    <option value="IL">Illinois
    <option value="IN">Indiana
    <option value="IA">Iowa
    <option value="KS">Kansas
    <option value="KY">Kentucky
    <option value="LA">Louisiana
    <option value="ME">Maine
    <option value="MD">Maryland
    <option value="MA">Massachusetts
    <option value="MI">Michigan
    <option value="MN">Minnesota
    <option value="MS">Mississippi
    <option value="MO">Missouri
    <option value="MT">Montana
    <option value="NE">Nebraska
    <option value="NV">Nevada
    <option value="NH">New Hampshire
    <option value="NJ">New Jersey
    <option value="NM">New Mexico
    <option value="NY">New York
    <option value="NC">North Carolina
    <option value="ND">North Dakota
    <option value="OH">Ohio
    <option value="OK">Oklahoma
    <option value="OR">Oregon
    <option value="PA">Pennsylvania
    <option value="RI">Rhode Island
    <option value="SC">South Carolina
    <option value="SD">South Dakota
    <option value="TN">Tennessee
    <option value="TX">Texas
    <option value="UT">Utah
    <option value="VT">Vermont
    <option value="VA">Virginia
    <option value="WA">Washington
    <option value="WV">West Virginia
    <option value="WI">Wisconsin
    <option value="WY">Wyoming
    </select>
    <input id="state" size="2" name="state">
     
    JRough, Oct 7, 2009
    #1
    1. Advertising

  2. Re: javascript drop down list for state state selection doesn'twork

    On Wed, 07 Oct 2009 09:15:37 -0700, JRough wrote:

    > Can you see what is wrong with this state field, form input? I get an
    > error in php that says Unknown column 'state' in 'field list' which
    > makes me think that the value isn't getting posted in the form. Can you
    > let me know I did wrong or if the Javascript is right? There is more to
    > the form I'm just giving you the field that doesnt' work. thanks,
    >
    > <label for="state">State</label>
    > <select id = "state" name = "state"> onChange="this.form.getElementByID
    > ("state").value=this[this.selectedIndex].value">
    > <option value="AL">Alabama
    > <option value="AK">Alaska
    > <option value="AZ">Arizona
    > <option value="AR">Arkansas
    > <option value="CA">California
    > <option value="CO">Colorado
    > <option value="CT">Connecticut
    > <option value="DE">Delaware
    > <option value="FL">Florida
    > <option value="GA">Georgia
    > <option value="HI">Hawaii
    > <option value="ID">Idaho
    > <option value="IL">Illinois
    > <option value="IN">Indiana
    > <option value="IA">Iowa
    > <option value="KS">Kansas
    > <option value="KY">Kentucky
    > <option value="LA">Louisiana
    > <option value="ME">Maine
    > <option value="MD">Maryland
    > <option value="MA">Massachusetts
    > <option value="MI">Michigan
    > <option value="MN">Minnesota
    > <option value="MS">Mississippi
    > <option value="MO">Missouri
    > <option value="MT">Montana
    > <option value="NE">Nebraska
    > <option value="NV">Nevada
    > <option value="NH">New Hampshire
    > <option value="NJ">New Jersey
    > <option value="NM">New Mexico
    > <option value="NY">New York
    > <option value="NC">North Carolina
    > <option value="ND">North Dakota
    > <option value="OH">Ohio
    > <option value="OK">Oklahoma
    > <option value="OR">Oregon
    > <option value="PA">Pennsylvania
    > <option value="RI">Rhode Island
    > <option value="SC">South Carolina
    > <option value="SD">South Dakota
    > <option value="TN">Tennessee
    > <option value="TX">Texas
    > <option value="UT">Utah
    > <option value="VT">Vermont
    > <option value="VA">Virginia
    > <option value="WA">Washington
    > <option value="WV">West Virginia
    > <option value="WI">Wisconsin
    > <option value="WY">Wyoming
    > </select>
    > <input id="state" size="2" name="state">


    Had you run your page through a validation service, you would have been
    informed that the id="state" is duplicated. This is, from what I can
    tell in a glance, the most likely cause of your problem.

    In general, it is better to either use a drop down -or- allow entering
    the state abbreviation (assuming that you are just within the US and
    Canada). Using both is unusual and apt to confuse users.
     
    Jeremy J Starcher, Oct 7, 2009
    #2
    1. Advertising

  3. JRough wrote:

    > Can you see what is wrong with this state field, form input?


    Yes, your markup is not Valid.

    <http://diveintomark.org/archives/2003/05/05/why_we_wont_help_you>


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Oct 7, 2009
    #3
  4. JRough

    Evertjan. Guest

    JRough wrote on 07 okt 2009 in comp.lang.javascript:

    > <select id = "state" name = "state"> onChange="this.form.getElementByID


    leave out the > on the above line

    > ("state").value=this[this.selectedIndex].value">
    > <option value="AL">Alabama



    However the below three codes do exactly the same:

    <select id = "state" name = "state"
    onChange="this.form.getElementByID("state").value=
    this[this.selectedIndex].value">

    <select id = "state" name = "state"
    onChange="this.value = this[this.selectedIndex].value">

    <select id = "state" name = "state">


    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Oct 7, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    531
    Cowboy \(Gregory A. Beamer\)
    Oct 6, 2006
  2. weiwei
    Replies:
    0
    Views:
    1,032
    weiwei
    Jan 5, 2007
  3. jaysch
    Replies:
    0
    Views:
    1,245
    jaysch
    Apr 30, 2011
  4. Replies:
    5
    Views:
    282
  5. JRough
    Replies:
    0
    Views:
    306
    JRough
    Oct 7, 2009
Loading...

Share This Page