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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Application crashing because of a "&" in string - Help

Status
Not open for further replies.

EduardoArias

Programmer
Jan 18, 2008
10
0
0
US
Greetings!

I have developed an application that generates quotes to our reps. Everything has been working out real good until today when I found out that one of the reps was having trouble creating a quote.

I analyzed the problem and I discovered that when the rep wrote the word "Aeronautical & General Instruments Limited" in one of the fields, the application crashes. However, I tested the word without the "&" and everything went well.

In java script I'm doing the following:



C
DistCustCompany = document.getElementByID('CustCompany').value;

I'm assuming that DistCustCompany is taking the value of string in this case, or not?

So, how can I either delete the "&" from a string? Or even better, how can make the DistCustCompany a real string?

I have already tried escape, but with no success as I get "%" in between words

Thank you!
 
You are doing it correctly. You would get a string back from the value property... so all is fine.

Prove it to yourself by making a small html file that tests it:
Code:
<html><head><title>Test Page</title>
<script type="text/javascript">
	function testCode() {
		var DistCustCompany = document.getElementById('CustCompany').value;
		alert(DistCustCompany);
	}
</script>
</head>
<body>
<form onsubmit="return false;">
<fieldset>
	<input type="text" id="CustCompany">
	<button name="test" onclick="testCode()">Test</button>
</fieldset>
</form>
</body>
</html>

I'm guessing your problem could be your use of getElementByI[!]D[/!] that last character should be lowercase: getElementById

Cheers,
Jeff

[tt]Visit my blog [!]@[/!] Visit Code Couch [!]@[/!] [/tt]

Make sure your web page and css validates properly against the doctype you have chosen - before you attempt to debug a problem!

FAQ216-6094
 
I see.

The getElementByID is not really affecting anything, so I will create the html page you are suggesting.

Thanks a lot man!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top