Page 1 of 1

Javascript Split - Illegal Character Error

Posted: Wed May 07, 2008 12:49 pm
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?

Re: Javascript Split - Illegal Character Error

Posted: Wed May 07, 2008 3:59 pm
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/

Re: Javascript Split - Illegal Character Error

Posted: Wed May 07, 2008 4:07 pm
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.

Re: Javascript Split - Illegal Character Error

Posted: Wed May 07, 2008 5:08 pm
by arjan.top
” and “ are illegal (" or ' are correct)