Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
|
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2003, 08:35 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to compare a string with the & sign in it?

I have this js script that is causing me problems becuase there is an ampersand (&) in comparison value in my if statement. I keep getting the error :'Unterminated string value'. How can I make it work so that I can use the value "ACA&BS" in an if statement?

if (form.dirvalue == "ACA&BS")
 { form.Domain.value="Resource & Cost Management";
}
 
Old June 12th, 2003, 08:39 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, you can do it like this:

if(String(form.dirvalue).search(/ACA(&|&)BS/) != -1){
   form.Domain.value="Resource & Cost Management";
}
 
Old June 12th, 2003, 11:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the post, but is there a simpler way to do it. The values
that I will be comparing are going to be pulled from a database and dynamically populated so I need an easier solutions to make values like AA&S, CC&M be used in an if statement.
 
Old June 13th, 2003, 02:25 AM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe like this:

var strDatabaseValue = "The string from the database";
var strToCompare = strDatabaseValue.replace(/&/gi, "&");
if(strToCompare == "ACA&BS"){
   form.Domain.value="Resource & Cost Management";
}


/Robert





Similar Threads
Thread Thread Starter Forum Replies Last Post
string compare in table field alxtech SQL Server 2000 1 April 27th, 2007 12:25 AM
Compare data & write Seb_soum Access ASP 1 June 4th, 2004 11:47 AM
including '<' or '>' sign in a string inside XML texasraven Classic ASP XML 1 February 26th, 2004 03:50 PM
Urgent help! Compare a string to Sysdate in Oracle WroteForLuck Classic ASP Basics 1 July 22nd, 2003 01:48 AM
Urgent help needed! Compare a string to Sysdate in WroteForLuck Classic ASP Professional 1 July 17th, 2003 06:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.