JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 8th, 2008, 07:35 PM
Saphirix Saphirix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 70 Saphirix User rank is Private First Class (20 - 50 Reputation Level)Saphirix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h 36 m 42 sec
Reputation Power: 4
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!

Reply With Quote
  #2  
Old May 8th, 2008, 10:17 PM
essee essee is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2008
Posts: 82 essee User rank is Sergeant (500 - 2000 Reputation Level)essee User rank is Sergeant (500 - 2000 Reputation Level)essee User rank is Sergeant (500 - 2000 Reputation Level)essee User rank is Sergeant (500 - 2000 Reputation Level)essee User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 7 h 27 m 10 sec
Reputation Power: 12
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.

Reply With Quote
  #3  
Old May 9th, 2008, 01:04 AM
jsKid's Avatar
jsKid jsKid is offline
Application is what Divides Us
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Dec 2002
Location: Titusville, FL
Posts: 2,108 jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level)jsKid User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 19 h 4 m 29 sec
Reputation Power: 50
Send a message via AIM to jsKid Send a message via MSN to jsKid
MySpace
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 !

Reply With Quote
  #4  
Old May 9th, 2008, 03:38 PM
Saphirix Saphirix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 70 Saphirix User rank is Private First Class (20 - 50 Reputation Level)Saphirix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h 36 m 42 sec
Reputation Power: 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!

Reply With Quote
  #5  
Old May 10th, 2008, 01:03 PM
romario romario is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 103 romario User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 2 m 34 sec
Reputation Power: 6
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

Reply With Quote
  #6  
Old May 13th, 2008, 03:19 PM
Saphirix Saphirix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2005
Posts: 70 Saphirix User rank is Private First Class (20 - 50 Reputation Level)Saphirix User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 11 h 36 m 42 sec
Reputation Power: 4
Quote:
Originally Posted by romario
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


Thanks Romario, thanks everyone I got this solved!

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > String cuts off after &


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway