southbeach
Programmer
I have an HTML form which contains a selection box which in turn is formed by using
The above is called via AJAX after executing the following javascript
These produce a selection box that looks like this
Notice what appears to be a newline or carriage return to the left of the state code. I have spent a great deal of time looking at this code and I just cannot put my finger on it.
Can you guys/gals see the problem? Have you any idea what may be?
BTW, I have tried adding trim(), str_replace() and a number of other function and nothing ...
Thank you all in advance for your help!
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
Code:
function StateArrayList() {
$string='
:All~
AL:Alabama~
AK:Alaska~
AB:Alberta~
AZ:Arizona~
AR:Arkansas~
BC:British Columbia~
CA:California~
CO:Colorado~
CT:Connecticut~
DE:Delaware~
DC:Dist. of Columbia~
FL:Florida~
GA:Georgia~
HI:Hawaii~
ID:Idaho~
IL:Illinois~
IN:Indiana~
IA:Iowa~
KS:kansas~
KY:Kentucky~
LA:Louisiana~
ME:Maine~
MB:Manitoba~
MD:Maryland~
MA:Massachusetts~
MX:Mexico~
MI:Michigan~
MN:Minnesota~
MS:Mississippi~
MO:Missouri~
MT:Montana~
NE:Nebraska~
NV:Nevada~
NB:New Brunswick~
NL:Newfoundland and Labrador~
NH:New Hampshire~
NJ:New Jersey~
NM:New Mexico~
NY:New York~
NC:North Carolina~
ND:North Dakota~
NS:Nova Scotia~
OH:Ohio~
OK:Oklahoma~
ON:Ontario~
OR:Oregon~
PA:Pennsylvania~
PE:Prince Edward Island~
QC:Quebec~
RI:Rhode Island~
SK:Saskatchewan~
SC:South Carolina~
SD:South Dakota~
TN:Tennessee~
TX:Texas~
UT:Utah~
VT:Vermont~
VA:Virginia~
WA:Washington~
WV:West Virginia~
WI:Wisconsin~
WY:Wyoming';
return($string);
}
function SelectStateOptions($state='') {
$array=StateArrayList();
$options='';
foreach(explode("~", $array) as $arg) {
list($code,$name)=explode(":", $arg);
$options.='<option value="'.trim($code).'"'.( (strtoupper($state) == strtoupper($code))?" selected ":"").'>'.$name.'</option>';
}
return($options);
}
The above is called via AJAX after executing the following javascript
Code:
function BuildFormValueArray(myForm)
{
var elem = document.getElementById(myForm).elements;
for(var i = 0; i < elem.length; i++)
{
if(elem[i].type=="checkbox" || elem[i].type=="text" || elem[i].type=="radio" || elem[i].type=="select" || elem[i].type=="select-one" || elem[i].type=="hidden") {
if(elem[i].type=="select" || elem[i].type=="select-one") {
formFieldsArray = formFieldsArray+elem[i].name+"::"+elem[i].options[elem[i].selectedIndex].value+"~";
} else {
if(elem[i].type=="checkbox" || elem[i].type=="radio") {
if(elem[i].checked) {
formFieldsArray = formFieldsArray+elem[i].name+'::'+elem[i].value+'~';
} else {
formFieldsArray = formFieldsArray+elem[i].name+'::0~';
}
} else {
formFieldsArray = formFieldsArray+elem[i].name+'::'+elem[i].value+'~';
}
}
}
}
}
Code:
<select name="originstate" id="originstate"><option value="
">All</option><option value="
AL">Alabama</option><option value="
AK">Alaska</option><option value="
AB">Alberta</option><option value="
AZ">Arizona</option><option value="
AR">Arkansas</option><option value="
BC">British Columbia</option><option value="
CA">California</option><option value="
CO">Colorado</option><option value="
CT">Connecticut</option><option value="
DE">Delaware</option><option value="
DC">Dist. of Columbia</option><option value="
FL">Florida</option><option value="
GA">Georgia</option><option value="
HI">Hawaii</option><option value="
ID">Idaho</option><option value="
IL">Illinois</option><option value="
IN">Indiana</option><option value="
IA">Iowa</option><option value="
KS">kansas</option><option value="
KY">Kentucky</option><option value="
LA">Louisiana</option><option value="
ME">Maine</option><option value="
MB">Manitoba</option><option value="
MD">Maryland</option><option value="
MA">Massachusetts</option><option value="
MX">Mexico</option><option value="
MI">Michigan</option><option value="
MN">Minnesota</option><option value="
MS">Mississippi</option><option value="
MO">Missouri</option><option value="
MT">Montana</option><option value="
NE">Nebraska</option><option value="
NV">Nevada</option><option value="
NB">New Brunswick</option><option value="
NL">Newfoundland and Labrador</option><option value="
NH">New Hampshire</option><option value="
NJ">New Jersey</option><option value="
NM">New Mexico</option><option value="
NY">New York</option><option value="
NC">North Carolina</option><option value="
ND">North Dakota</option><option value="
NS">Nova Scotia</option><option value="
OH">Ohio</option><option value="
OK">Oklahoma</option><option value="
ON">Ontario</option><option value="
OR">Oregon</option><option value="
PA">Pennsylvania</option><option value="
PE">Prince Edward Island</option><option value="
QC">Quebec</option><option value="
RI">Rhode Island</option><option value="
SK">Saskatchewan</option><option value="
SC">South Carolina</option><option value="
SD">South Dakota</option><option value="
TN">Tennessee</option><option value="
TX">Texas</option><option value="
UT">Utah</option><option value="
VT">Vermont</option><option value="
VA">Virginia</option><option value="
WA">Washington</option><option value="
WV">West Virginia</option><option value="
WI">Wisconsin</option><option value="
WY">Wyoming</option></select></td>
<td><select name="deststate" id="deststate"><option value="
">All</option><option value="
AL">Alabama</option><option value="
AK">Alaska</option><option value="
AB">Alberta</option><option value="
AZ">Arizona</option><option value="
AR">Arkansas</option><option value="
BC">British Columbia</option><option value="
CA">California</option><option value="
CO">Colorado</option><option value="
CT">Connecticut</option><option value="
DE">Delaware</option><option value="
DC">Dist. of Columbia</option><option value="
FL">Florida</option><option value="
GA">Georgia</option><option value="
HI">Hawaii</option><option value="
ID">Idaho</option><option value="
IL">Illinois</option><option value="
IN">Indiana</option><option value="
IA">Iowa</option><option value="
KS">kansas</option><option value="
KY">Kentucky</option><option value="
LA">Louisiana</option><option value="
ME">Maine</option><option value="
MB">Manitoba</option><option value="
MD">Maryland</option><option value="
MA">Massachusetts</option><option value="
MX">Mexico</option><option value="
MI">Michigan</option><option value="
MN">Minnesota</option><option value="
MS">Mississippi</option><option value="
MO">Missouri</option><option value="
MT">Montana</option><option value="
NE">Nebraska</option><option value="
NV">Nevada</option><option value="
NB">New Brunswick</option><option value="
NL">Newfoundland and Labrador</option><option value="
NH">New Hampshire</option><option value="
NJ">New Jersey</option><option value="
NM">New Mexico</option><option value="
NY">New York</option><option value="
NC">North Carolina</option><option value="
ND">North Dakota</option><option value="
NS">Nova Scotia</option><option value="
OH">Ohio</option><option value="
OK">Oklahoma</option><option value="
ON">Ontario</option><option value="
OR">Oregon</option><option value="
PA">Pennsylvania</option><option value="
PE">Prince Edward Island</option><option value="
QC">Quebec</option><option value="
RI">Rhode Island</option><option value="
SK">Saskatchewan</option><option value="
SC">South Carolina</option><option value="
SD">South Dakota</option><option value="
TN">Tennessee</option><option value="
TX">Texas</option><option value="
UT">Utah</option><option value="
VT">Vermont</option><option value="
VA">Virginia</option><option value="
WA">Washington</option><option value="
WV">West Virginia</option><option value="
WI">Wisconsin</option><option value="
WY">Wyoming</option></select>
Notice what appears to be a newline or carriage return to the left of the state code. I have spent a great deal of time looking at this code and I just cannot put my finger on it.
Can you guys/gals see the problem? Have you any idea what may be?
BTW, I have tried adding trim(), str_replace() and a number of other function and nothing ...
Thank you all in advance for your help!
--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.