|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
String cuts off after &
I have a problem with using & in a string coming from a form field.
For example, I have a <textarea> field setup like this: Code:
<textarea id="contents" name="contents"></textarea> And if inside I input the following: Jack & Daniels and I then after a clicking for a submission, it does a: Code:
div.element.innerHTML = document.getElementById('contents').value;
I would get the results looking like: Jack and everything after the & would just be cutoff completely. Now I have absolutely NO idea what's going on there. If I did a: Code:
alert(document.getElementById('contents').value);
That would actually pop-up a dialog box with: Jack & Daniels like it should... Do I need to format the string in someway before I pass it into the DIV? I thought about doing a ".replace()" on the & but I then I started thinking ahead, what if I come up with more characters I put into the fields and they also cut off the string? I am hoping to find an overall fix for this, I just dunno what to specifically look for. Any help would be appreciated, thanks! |
|
#2
|
|||
|
|||
|
Hi,
Not sure if this Code:
div.element.innerHTML = document.getElementById('contents').value;
is your actual code or not but you should be referencing elements by id like Code:
document.getElementById('element').innerHTML = document.getElementById('contents').value;
Should work fine. And running the code like that worked no problems for me with all characters. Edit: I didn't actually submit the form in testing because I have no idea what your doing with it. You probably need to save the value of the text area to a variable and then on the new page after submission call another function to show it in the 'element' div. Last edited by essee : May 8th, 2008 at 10:22 PM. |
|
#3
|
||||
|
||||
|
You might as well cover any future development by replacing all
instances of the ampersand with Code:
& a m p ;
__________________
Download [ Fx | Op ] Validate [ Markup | Css ] Code:
javascript per the (do ... while loop) Almost sounds like an introduction... haha great ! |
|
#4
|
|||
|
|||
|
Thanks for the inputs... I used "escape()" and that worked for the &, but now there's a new problem... when the field contains a | it will cut off from there...
Ugh! ![]() |
|
#5
|
|||
|
|||
|
i am no javascript expert but try this: http://www.the-art-of-web.com/javascript/escape/
one of those functions may work esp encodeURIComponent |
|
#6
|
|||
|
|||
|
Quote:
Thanks Romario, thanks everyone I got this solved! |
![]() |
| Viewing: Dev Shed Forums > Web Design > JavaScript Development > String cuts off after & |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|