Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help with invisible character or one I cannot reveal in any way I know of 1

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
I have an HTML form which contains a selection box which in turn is formed by using
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+'~';
						}
					}
				}
			}
		}
These produce a selection box that looks like this
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.
 
Worth mentioning is that my problem is NOT the way the selection tables look but once the form is submitted, the value of the chosen state(s) seem to have a character I cannot identify.

So, instead of a code looking like "NY", it looks like " NY"

Because of this, when comparing to other "expecting matching strings", I get FALSE instead of TRUE conditions.


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
It is most probably a carriage return.

The why?: Its because your state list has these carriage returns physically in there.

Code:
function StateArrayList() {
$string='[b]¶[/b]
:All~[b]¶[/b]
AL:Alabama~[b]¶[/b]
AK:Alaska~[b]¶[/b]
AB:Alberta~[b]¶[/b]
AZ:Arizona~[b]¶[/b]
AR:Arkansas~[b]¶[/b]
...

When you split the values by the "~" character you get the carriage return that is physically in your list with them. so it gets transported as part of the string out onto the dropdown and gets submitted as part of the value to your processing script.

You have 2 choices here, either remove all carriage returns from your list so it becomes a single line:
Code:
$string='
:All~AL:Alabama~AK:Alaska~AB:Alberta~AZ:Arizona~AR:Arkansas~...';

Or my personal choice, to keep the list more readable, is explode by carriage return rather than tilde. Just remove the tildes at the end of your entries, and change your explode call like so:

Code:
foreach(explode("[COLOR=#5C3566][b]\r\n[/b][/color]", $array) as $arg) {
		list($code,$name)=explode(":", $arg);
		$options.='<option value="'.trim($code).'"'.( (strtoupper($state) == strtoupper($code))?" selected ":"").'>'.$name.'</option>';
	}

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Web & Tech
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top