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

J

JRough

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">
 
J

Jeremy J Starcher

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.
 
E

Evertjan.

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">
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top