asaworker
asked on
Issue with emdashes when comparing 2 strings
I'm trying to compare a form value with an array value. It turnsd out the issue is with the unicde equivalent of an emdash — that's stored in the database. Any way to convert it on the client side, or any other workarounds.
The code is below:
<html>
<script>
//STORE THE Product and its COST in an array, You can generate this section using your Server script
var arProductA=new Array();
arProductA[0]=new Array(3);
arProductA[0][0]="TESTA";
arProductA[0][1]="Boston";
arProductA[0][2]="Massachu setts";
arProductA[1]=new Array(3);
arProductA[1][0]="Embassy Suites—Nashville-Sou th/Cool Springs";
arProductA[1][1]="Franklin ";
arProductA[1][2]="Tennesse e";
arProductA[2]=new Array(3);
arProductA[2][0]="Embassy Suites—San Francisco";
arProductA[2][1]="South San Francisco";
arProductA[2][2]="Californ ia";
arProductA[3]=new Array(3);
arProductA[3][0]="Embassy Suites—Santa Ana";
arProductA[3][1]="Santa Ana";
arProductA[3][2]="Californ ia";
arProductA[4]=new Array(3);
arProductA[4][0]="Grand Canyon University";
arProductA[4][1]="Phoenix" ;
arProductA[4][2]="Arizona" ;
arProductA[5]=new Array(3);
arProductA[5][0]="Holiday Inn—Buena Park Hotel & Conference Center";
arProductA[5][1]="Buena Park";
arProductA[5][2]="Californ ia";
arProductA[6]=new Array(3);
arProductA[6][0]="Long Island Marriott Hotel & Conference Center";
arProductA[6][1]="Uniondal e";
arProductA[6][2]="New York";
arProductA[7]=new Array(3);
arProductA[7][0]="Pima Community College Community Campus";
arProductA[7][1]="Tucson";
arProductA[7][2]="Arizona" ;
arProductA[8]=new Array(3);
arProductA[8][0]="Sherwood Inn";
arProductA[8][1]="Skaneate les";
arProductA[8][2]="New York";
arProductA[9]=new Array(3);
arProductA[9][0]="Universi ty of Alaska";
arProductA[9][1]="Anchorag e";
arProductA[9][2]="Alaska";
arProductA[10]=new Array(3);
arProductA[10][0]="Univers ity of Phoenix—Hohokam Campus";
arProductA[10][1]="Phoenix ";
arProductA[10][2]="Arizona ";
function populate(oCbo)
{
var oProdA = document.theForm.venue;
var oCostA = document.theForm.location;
var oCost2A = document.theForm.location_ state;
if (oProdA.selectedIndex !=0)
{
//SHOW THE COST
for(var j=0; j<arProductA.length; j++){
if(oProdA.value==arProduct A[j][0])
{
oCostA.value = arProductA[j][1];
oCost2A.value = arProductA[j][2];
}
}
}
else
{
oCostA.value = "";
oCost2A.value = "";
}
}
</script>
<body>
<form name="theForm">
<select name="venue" onChange="populate();">
<option value="">—SelectR 12;</optio n>
<option value="TESTA">TESTA</optio n>
<option class="state" value="Embassy Suites—Nashville-Sou th/Cool Springs">Embassy Suites—Nashville-Sou th/Cool Springs</option>
<option class="state" value="Embassy Suites—San Francisco">Embassy Suites—San Francisco</option>
<option class="state" value="Embassy Suites—Santa Ana">Embassy Suites—Santa Ana</option>
<option class="state" value="Grand Canyon University">Grand Canyon University</option>
<option class="state" value="Holiday Inn—Buena Park Hotel & Conference Center">Holiday Inn—Buena Park Hotel & Conference Center</option>
<option class="state" value="Long Island Marriott Hotel & Conference Center">Long Island Marriott Hotel & Conference Center</option>
<option class="state" value="Pima Community College Community Campus">Pima Community College Community Campus</option>
<option class="state" value="Sherwood Inn">Sherwood Inn</option>
<option class="state" value="University of Alaska">University of Alaska</option>
<option class="state" value="University of Phoenix—Hohokam Campus">University of Phoenix—Hohokam Campus</option>
</select>
<input type="text" name="location" value=""><br>
<input type="text" name="location_state" value="">
</form>
</body>
</html>
The code is below:
<html>
<script>
//STORE THE Product and its COST in an array, You can generate this section using your Server script
var arProductA=new Array();
arProductA[0]=new Array(3);
arProductA[0][0]="TESTA";
arProductA[0][1]="Boston";
arProductA[0][2]="Massachu
arProductA[1]=new Array(3);
arProductA[1][0]="Embassy Suites—Nashville-Sou
arProductA[1][1]="Franklin
arProductA[1][2]="Tennesse
arProductA[2]=new Array(3);
arProductA[2][0]="Embassy Suites—San Francisco";
arProductA[2][1]="South San Francisco";
arProductA[2][2]="Californ
arProductA[3]=new Array(3);
arProductA[3][0]="Embassy Suites—Santa Ana";
arProductA[3][1]="Santa Ana";
arProductA[3][2]="Californ
arProductA[4]=new Array(3);
arProductA[4][0]="Grand Canyon University";
arProductA[4][1]="Phoenix"
arProductA[4][2]="Arizona"
arProductA[5]=new Array(3);
arProductA[5][0]="Holiday Inn—Buena Park Hotel & Conference Center";
arProductA[5][1]="Buena Park";
arProductA[5][2]="Californ
arProductA[6]=new Array(3);
arProductA[6][0]="Long Island Marriott Hotel & Conference Center";
arProductA[6][1]="Uniondal
arProductA[6][2]="New York";
arProductA[7]=new Array(3);
arProductA[7][0]="Pima Community College Community Campus";
arProductA[7][1]="Tucson";
arProductA[7][2]="Arizona"
arProductA[8]=new Array(3);
arProductA[8][0]="Sherwood
arProductA[8][1]="Skaneate
arProductA[8][2]="New York";
arProductA[9]=new Array(3);
arProductA[9][0]="Universi
arProductA[9][1]="Anchorag
arProductA[9][2]="Alaska";
arProductA[10]=new Array(3);
arProductA[10][0]="Univers
arProductA[10][1]="Phoenix
arProductA[10][2]="Arizona
function populate(oCbo)
{
var oProdA = document.theForm.venue;
var oCostA = document.theForm.location;
var oCost2A = document.theForm.location_
if (oProdA.selectedIndex !=0)
{
//SHOW THE COST
for(var j=0; j<arProductA.length; j++){
if(oProdA.value==arProduct
{
oCostA.value = arProductA[j][1];
oCost2A.value = arProductA[j][2];
}
}
}
else
{
oCostA.value = "";
oCost2A.value = "";
}
}
</script>
<body>
<form name="theForm">
<select name="venue" onChange="populate();">
<option value="">—SelectR
<option value="TESTA">TESTA</optio
<option class="state" value="Embassy Suites—Nashville-Sou
<option class="state" value="Embassy Suites—San Francisco">Embassy Suites—San Francisco</option>
<option class="state" value="Embassy Suites—Santa Ana">Embassy Suites—Santa Ana</option>
<option class="state" value="Grand Canyon University">Grand Canyon University</option>
<option class="state" value="Holiday Inn—Buena Park Hotel & Conference Center">Holiday Inn—Buena Park Hotel & Conference Center</option>
<option class="state" value="Long Island Marriott Hotel & Conference Center">Long Island Marriott Hotel & Conference Center</option>
<option class="state" value="Pima Community College Community Campus">Pima Community College Community Campus</option>
<option class="state" value="Sherwood Inn">Sherwood Inn</option>
<option class="state" value="University of Alaska">University of Alaska</option>
<option class="state" value="University of Phoenix—Hohokam Campus">University of Phoenix—Hohokam Campus</option>
</select>
<input type="text" name="location" value=""><br>
<input type="text" name="location_state" value="">
</form>
</body>
</html>
The removed the characters I am trying again in the code snippet to see if that works
//STORE THE Product and its COST in an array, You can generate this section using your Server script
var arProductA=new Array();
arProductA[0]=new Array(3);
arProductA[0][0]="TESTA";
arProductA[0][1]="Boston";
arProductA[0][2]="Massachusetts";
arProductA[1]=new Array(3);
arProductA[1][0]="Embassy SuitesNashville-South/Cool Springs";
arProductA[1][1]="Franklin";
arProductA[1][2]="Tennessee";
arProductA[2]=new Array(3);
arProductA[2][0]="Embassy SuitesSan Francisco";
arProductA[2][1]="South San Francisco";
arProductA[2][2]="California";
arProductA[3]=new Array(3);
arProductA[3][0]="Embassy SuitesSanta Ana";
arProductA[3][1]="Santa Ana";
arProductA[3][2]="California";
arProductA[4]=new Array(3);
arProductA[4][0]="Grand Canyon University";
arProductA[4][1]="Phoenix";
arProductA[4][2]="Arizona";
arProductA[5]=new Array(3);
arProductA[5][0]="Holiday InnBuena Park Hotel & Conference Center";
arProductA[5][1]="Buena Park";
arProductA[5][2]="California";
arProductA[6]=new Array(3);
arProductA[6][0]="Long Island Marriott Hotel & Conference Center";
arProductA[6][1]="Uniondale";
arProductA[6][2]="New York";
arProductA[7]=new Array(3);
arProductA[7][0]="Pima Community College Community Campus";
arProductA[7][1]="Tucson";
arProductA[7][2]="Arizona";
arProductA[8]=new Array(3);
arProductA[8][0]="Sherwood Inn";
arProductA[8][1]="Skaneateles";
arProductA[8][2]="New York";
arProductA[9]=new Array(3);
arProductA[9][0]="University of Alaska";
arProductA[9][1]="Anchorage";
arProductA[9][2]="Alaska";
arProductA[10]=new Array(3);
arProductA[10][0]="University of PhoenixHohokam Campus";
arProductA[10][1]="Phoenix";
arProductA[10][2]="Arizona";
ASKER
I figured that was the issue after looking at it for awhile. Do you have an example using coldfusion?
I guess not.... Just make sure to replace the — with the actual emdash character when you are generating the array javascript
something like this:
arProductA[4][0]="#replace (myquery.h otelname,' ##8212;',c hr(8212)," ALL")#";
arProductA[4][0]="#replace
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
ANy idea how to add another zone for this question?
I don't know... probably community support
ASKER
Perfect, this worked. Any idea how to add 8217 to it as well?
This is what worekd: arLocationA[#i#][0]="#repl ace(locati onname,'&# #8212;',ch r(8212),'A LL')#";
This is what worekd: arLocationA[#i#][0]="#repl
#replace(#replace(location name,'&##8 212;',chr( 8212),'ALL ')#,'&##82 17;',chr(8 217),'ALL' )#
oops sorry too many #'s should be:
#replace(replace(locationn ame,'&##82 12;',chr(8 212),'ALL' ),'&##8217 ;',chr(821 7),'ALL')#
#replace(replace(locationn
ASKER
Thanks SBenmnet, this is good to know, I appreciate all your help.
You can see this if you add an alert to dump out the two strings being compared withing your loop:
//SHOW THE COST
for(var j=0; j<arProductA.length; j++){
alert(oProdA.value + "\n" + arProductA[j][0]);
if(oProdA.value==arProduct
{
oCostA.value = arProductA[j][1];
oCost2A.value = arProductA[j][2];
}
}
The easiest way to resolve this is to use your server side scripting language to replace — with when you are creating the javascript array so that your array source looks like:
//STORE THE Product and its COST in an array, You can generate this section using your Server script
var arProductA=new Array();
arProductA[0]=new Array(3);
arProductA[0][0]="TESTA";
arProductA[0][1]="Boston";
arProductA[0][2]="Massachu
arProductA[1]=new Array(3);
arProductA[1][0]="Embassy SuitesNashville-South/Coo
arProductA[1][1]="Franklin
arProductA[1][2]="Tennesse
arProductA[2]=new Array(3);
arProductA[2][0]="Embassy SuitesSan Francisco";
arProductA[2][1]="South San Francisco";
arProductA[2][2]="Californ
arProductA[3]=new Array(3);
arProductA[3][0]="Embassy SuitesSanta Ana";
arProductA[3][1]="Santa Ana";
arProductA[3][2]="Californ
arProductA[4]=new Array(3);
arProductA[4][0]="Grand Canyon University";
arProductA[4][1]="Phoenix"
arProductA[4][2]="Arizona"
arProductA[5]=new Array(3);
arProductA[5][0]="Holiday InnBuena Park Hotel & Conference Center";
arProductA[5][1]="Buena Park";
arProductA[5][2]="Californ
arProductA[6]=new Array(3);
arProductA[6][0]="Long Island Marriott Hotel & Conference Center";
arProductA[6][1]="Uniondal
arProductA[6][2]="New York";
arProductA[7]=new Array(3);
arProductA[7][0]="Pima Community College Community Campus";
arProductA[7][1]="Tucson";
arProductA[7][2]="Arizona"
arProductA[8]=new Array(3);
arProductA[8][0]="Sherwood
arProductA[8][1]="Skaneate
arProductA[8][2]="New York";
arProductA[9]=new Array(3);
arProductA[9][0]="Universi
arProductA[9][1]="Anchorag
arProductA[9][2]="Alaska";
arProductA[10]=new Array(3);
arProductA[10][0]="Univers
arProductA[10][1]="Phoenix
arProductA[10][2]="Arizona