Javascript Split - Illegal Character Error

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Javascript Split - Illegal Character Error

Post by SpecialK »

When using the following code, I am experiencing an illegal character error.
I pass the index, and names of the IDs to find the other data to update. No matter what 'unique character' I have tried to split on, it gives me an error such as
illegal character
[Break on this error] var ad = addr.split(”?“);\n

Code: Select all

function populate(selectedIndex,numID,nameID,addrID,phoneID){
  alert(selectedIndex+"\n"+numID+"\n"+nameID+"\n"+addrID+"\n"+phoneID);
 
  document.getElementById(numID).value = numbers[selectedIndex];
  document.getElementById(nameID).value = names[selectedIndex];
  
  addr = address[selectedIndex];
  var ad = addr.split(”?“);
  var adOut = ad[0]."\n".ad[1]."\n".ad[2].", ".ad[3]."\n".ad[4];
  document.getElementById(addrID).value = adOut;
  document.getElementById(phoneID).value = phones[selectedIndex];
  
}
 
I haven't been able to find any documentation saying there are restricted characters. I have also tried escaping the characters with a \, but that gave the same error.
As a note, address is a textarea, so I am wanting to split and create newlines where required. If I did this before it was pushed into the array, I would get an unterminated string error.

Any ideas on what I am doing incorrectly, or a better solution for this problem?
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Re: Javascript Split - Illegal Character Error

Post by kendall »

i dont know if i can solve your problem but if your looking for some "word split" or "word wrap"

try

http://kevin.vanzonneveld.net/techblog/ ... _wordwrap/
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: Javascript Split - Illegal Character Error

Post by SpecialK »

The data comes from a delimited file, so although in PHP I can split on characters and then create newlines (which I want to do here) it gives me the string error.
I don't know if wordwrap is the way to go, but that link has a lot of similar functionality that I may need. Thanks for that and I will try with some of the code on that site and see how things go.
User avatar
arjan.top
Forum Contributor
Posts: 305
Joined: Sun Oct 14, 2007 4:36 am
Location: Hoče, Slovenia

Re: Javascript Split - Illegal Character Error

Post by arjan.top »

” and “ are illegal (" or ' are correct)
Post Reply