473,729 Members | 2,105 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to handle special characters within html options?

Hi folks,

I have a list of entries where some entries contain the special
character ["] (quotes) within in the string. If I try to save this
entry everything after the quotes is skipped. The reason for this is
quite obvious, since the resulting html tag looks like this:

<option value="go "again" selected="selec ted">nochmal
&quot;go</option>

I want to enable the user to insert any char sequence without forcing
him to escape such special characters (in this case [go "again]).
Does anyone have an idea how to achieve this. Is it possible to call a
js function that converts all entries of a select box to "secure"
strings?

TIA

Frank
fr***********@n ojunk.hotmail.c om
Jul 20 '05 #1
8 22742


Frank Ratzlow wrote:
Hi folks,

I have a list of entries where some entries contain the special
character ["] (quotes) within in the string. If I try to save this
entry everything after the quotes is skipped. The reason for this is
quite obvious, since the resulting html tag looks like this:

<option value="go "again" selected="selec ted">nochmal
&quot;go</option>


It doesn't have to do anything with Javascript, within HTML you need to
escape the quote
<option value="go &quot;again"

--

Martin Honnen
http://JavaScript.FAQTs.com/

Jul 20 '05 #2
jep, I know but is there any way to transparently convert the '"' to
the quoted version because I don't want to expect users to do this on
their own.
One thing I could image would be to run a js function on submit of the
form that parses the fields for this char and converts it before
sending the form to the server. The next time the value is retrieved
from the server it is already quoted.
But, how to do this, since I cannot simple replace this one char with
a char sequence the quotation is.
Any idea?

Frank

Martin Honnen <Ma***********@ t-online.de> wrote in message news:<3F******* *******@t-online.de>...
Frank Ratzlow wrote:
Hi folks,

I have a list of entries where some entries contain the special
character ["] (quotes) within in the string. If I try to save this
entry everything after the quotes is skipped. The reason for this is
quite obvious, since the resulting html tag looks like this:

<option value="go "again" selected="selec ted">nochmal
&quot;go</option>


It doesn't have to do anything with Javascript, within HTML you need to
escape the quote
<option value="go &quot;again"

Jul 20 '05 #3
"Frank Ratzlow" <fr***********@ hotmail.com> schrieb im Newsbeitrag
news:5e******** *************** ***@posting.goo gle.com...
jep, I know but is there any way to transparently convert the '"' to
the quoted version because I don't want to expect users to do this on
their own.
One thing I could image would be to run a js function on submit of the
form that parses the fields for this char and converts it before
sending the form to the server. The next time the value is retrieved
from the server it is already quoted.
But, how to do this, since I cannot simple replace this one char with
a char sequence the quotation is.
Any idea?


You can urlencode all values before inserting them into the database and
urldecode them only on display. But you better do this on the server side
than with Javascript.

--
Markus
Jul 20 '05 #4
Markus Ernst wrote on 20 aug 2003 in comp.lang.javas cript:
You can urlencode all values before inserting them into the database and
urldecode them only on display. But you better do this on the server side
than with Javascript.


Javascript can be used clientside and serverside,
the latter on an ASP platform.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #5
Hi,

correct me if I'm wrong but this will (as the name implies) only work
for request parameters wich are appended to the url. But if the values
are stored as request attributes this won't be that easy.
We are using the JSP / Struts and values of the HTML form are passed
along with a Struts ActionForm class (in conjunction with struts-html
and jstl taglibs).
My concerns are, if I store such an urlencoded value in the db than it
will be difficult to lookup these values from a db since queries don't
take into account the encoding.
Any idea?

TIA

Frank

"Markus Ernst" <de******@yahoo .com> wrote in message news:<3f******* ***@news.bluewi n.ch>...
"Frank Ratzlow" <fr***********@ hotmail.com> schrieb im Newsbeitrag
news:5e******** *************** ***@posting.goo gle.com...
jep, I know but is there any way to transparently convert the '"' to
the quoted version because I don't want to expect users to do this on
their own.
One thing I could image would be to run a js function on submit of the
form that parses the fields for this char and converts it before
sending the form to the server. The next time the value is retrieved
from the server it is already quoted.
But, how to do this, since I cannot simple replace this one char with
a char sequence the quotation is.
Any idea?


You can urlencode all values before inserting them into the database and
urldecode them only on display. But you better do this on the server side
than with Javascript.

Jul 20 '05 #6
Hi Fred,

thanx for your reply.
Here is a page that shows how the look of the field construct is. I
left all the js bound to the arrows because it's a lot.
=============== =============== =============
<html>
<head><title/></head>
<body>
<table valign="top" cellspacing="0" cellpadding="0" border="0" >
<tr>
<td>
<select name="valueArra y" multiple="multi ple" id="valueArrayF ield">
<option value="ich bin dein test du bist mein user"
selected="selec ted">dummy entry</option>
</select>
</td>
<td>
<table>
<tr>
<td>
<a href="javascrip t:void(0);"><<</a>
</td>
<td>
<input tabindex="3" class="field" type="text"
id="inputField " size="20" ></td>
</tr>
<tr>
<td>
<a href="javascrip t:void(0);">>></a>
</td>
</tr>
<tr>
<td>
<a href="javascrip t:void(0);">-</a>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
=============== =============== =============

The JS bound to the arrows moves values between valueArrayField and
inputField. When I click on the right arrow (<<) then a new entered
string in inputField should be appended to the option list of the
valueArrayField . I already included some parsing to see if there are ,
or ; to move multiple values. I can also append values that contain
this damn ' " ' and they appear as an option in the valueArrayField .
But you are right, the value will of course be truncated after the
second quotes.
So what could imagine to to is to include a (preferabel short)
function that does a simple replace if a quote is found.
So when I click on the (<<) the new string will first be parsed for
quotes and every quote will be substituted with the corresponding
'&quot;'. All this should happen _before_ a new option object is
created, so that i don't run into trouble with the html renderer of
the browser.
Do you know how to just replace one char with a sequence of chars?

TIA

Frank
Fred Basset <fr*********@wh osyourdaddy.com > wrote in message news:<3f******* **************@ news.frii.net>. ..
I don't know how you will go about doing it from the JSP side, but I'll
explain why it's so difficult from a client-side JavaScript point of
view ...

You're presenting an HTML page (all the browser sees) which contains

<select name="someselec t">
<option value="some "value">som e text</option>
</select>

The problem is that until the HTML is parsed by the browser the element
itself won't exist to be referenced. Once it has been parsed you will
find that ...

someselect.opti ons[0].value == 'some ';

.. because as soon as it encounters a second double-quote it closes the
value attribute. There's no way of getting the full value of the element
out because of the way the document tree in an HTML page works. The only
way you would be able to do it is if you can parse the page line by
line, instead of in its tree form, but you won't be able to do that
using client-side JavaScript.

Your only options as I see it are to parse the page yourself before
sending it to the browser and do your replace there, or to use custom
taglibs instead of the standard ones in your JSPs (or handcode it the
old-fashioned way), thereby bypassing the problem and letting
String.replaceA ll() do your work for you.

Hope I've made sense, and that I've not overlooked a glaringly obvious
solution to all your problems :)

Fred Basset
fr*********@who syourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #7
This appears to work for me ... pass in the field object (i.e. the text
box) and it will return a string with the quote marks replaced as you
wish.

function correct( oField )
{
var strCurr = oField.value;
var strNew = "";
var regWrong = /\"/;
var strRight = "&quot;"
for (i=0; i<strCurr.lengt h; i++)
strNew += strCurr.charAt( i).replace(regW rong,strRepl);
return strNew;
}

I'm only a beginner when it comes to proper Regexp usage, so there may
be a more efficient way of doing the same that I'm unaware of.

Fred Basset
fr*********@who syourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #8
Hi Fred,

I included (with some modification) your code but the results are very
strange.
The altered function is:

=============== =============== =============
function replaceSpecialC har(sourceStrin g) {
var strCurr = sourceString;
var strNew = "";
var strRight = "&quot;"

for (l=0; l<strCurr.lengt h; l++) {
(strCurr.charAt (l) == '"') ? strNew += strRight : strNew +=
strCurr.charAt( l);
}
return strNew;
}
=============== =============== =============

This is being called in a code fragment when from the input box
something is moved over to the combobox, namely a new Option is being
created. The relevant fragment looks like this:

=============== =============== =============
var text = srcfield.value;
var value = replaceSpecialC har(srcfield.va lue);
alert("converte d String \n" + "text: " + text + "\tvalue " +
value);
fieldtochange.o ptions[fieldtochange.o ptions.length] = new
Option(text,val ue);
=============== =============== =============

The thing is that the value to be displayed is stored in the text var
and the value to be saved (and not to truncated) value is stored in
value.
Okay, first of all I add my new value from the inputBox to the combox
-> works fine with all it's expected behaviour. I send the form to the
server where the option, exactly it's value is saved in a DB.
Now it comes! When I retrieve the value from the DB for display in the
list both value and and the text are stored/displayed as the the
encrypted version.
Okay, I save the form with this field a second time and refetch it
afterwards again. The result: the text is properly displayed (means
encrypted in html) but the value again isn't. Submitting and
retrieving same form again cuts the whole substring from the beginning
of ' " '.
=============== =============== ==========
1.) after the first save/refetch
<option value="let&quot ;s move" selected="selec ted">let&amp;qu ot;s
move</option></select>

2.) after second save/refetch
<option value="let"s move" selected="selec ted">let&quot; s
move</option></select>

3.) after third save/refetch
<option value="let" selected="selec ted">let</option></select>
=============== =============== ==========

To be honest I don't even know if the reason is the browser or the
server. Finally it really drives my crazy because it seems that there
is no way of moving around strings containing quotes.

Any idea will be appreciated

TIA

Frank

Fred Basset <fr*********@wh osyourdaddy.com > wrote in message news:<3f******* *************** *@news.frii.net >...
This appears to work for me ... pass in the field object (i.e. the text
box) and it will return a string with the quote marks replaced as you
wish.

function correct( oField )
{
var strCurr = oField.value;
var strNew = "";
var regWrong = /\"/;
var strRight = "&quot;"
for (i=0; i<strCurr.lengt h; i++)
strNew += strCurr.charAt( i).replace(regW rong,strRepl);
return strNew;
}

I'm only a beginner when it comes to proper Regexp usage, so there may
be a more efficient way of doing the same that I'm unaware of.

Fred Basset
fr*********@who syourdaddy.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2194
by: Paul | last post by:
Hi Doing my best to understand why I cant insert a vbcrlf or an equivalent into this piece of code that read messages from an SQL DB. The messages it takes read into a marquee fine but I want the Marquee to scroll up instead of horizontally and I need new line spacings else the mesages are difficult to read. At present we use the strNewTextDelimitor and I am unable due to syntax or perhaps idioscy to find a way of adding the VBCRLF...
3
6517
by: Jens Kristensen | last post by:
I have a problem displaying a divbox containing a html-textarea - everything works fine with "normal" characters. However, when the textarea contains special chars like <P> or ' , the box fails to show: function show(divbox) { divbox.style.display=''; } <div id="divbox" style="display:none" >
0
1423
by: hoenes1 | last post by:
Hi all, I have a standard html form containing several textboxes. Since this is a german application, the boxes are likely to contain special characters like ä, ö, ß, etc. The form is passed to the asp.net application via action="FormHandler.aspx" method="post". Evaluating the values in Request.Form.GetValues(key) yields the content of the textboxes omitting the special characters, for example typing "Rüdiger" (7 chars) in the form...
17
30669
by: Carl Mercier | last post by:
Hi, Is it possible to use special characters like \n or \t in a VB.NET string, just like in C#? My guess is NO, but maybe there's something I don't know. If it's not possible, does anybody know of a VB.NET function (somebody must have coded this already) that will interpret strings containings those special characters, and handle them the same as in C#?
8
3712
by: david.lindsay.green | last post by:
Hello all, I am quite new a web scripting and making web pages in general and I have stumbled across a problem I have as yet been unable to solve. I am trying to take the contents of a textarea box and save it to a file. This step is not to hard however the contents of the textarea is mostly latex source so it contains just about every special character you can imagine. My question is this, how do I save an exact copy of the textarea...
3
1578
by: grantges | last post by:
Hi - Does anyone know of a php function that takes a given character - ex. "A" without quotes and converts it into A ? If not a single function, what is the best way to accomplish this. The htmlentities function suite handle special characters, but my goal is to change average everyday letters of the alphabet as well. Thanks -
25
5379
by: Wim Cossement | last post by:
Hello, I was wondering if there are a few good pages and/or examples on how to process form data correctly for putting it in a MySQL DB. Since I'm not used to using PHP a lot, I already found out that addslashes() can be used escape some characters, but I'm having some more problems with for instance ä, å and µ (since the text is scientifical) Now some people also throw in htmlspecialchars() to convert those to HTML entities, but some...
3
4358
by: raga | last post by:
Hi Could you please let me know When i specify an attribute of an XML Tag as CDATA in DTD , can i use & straight away within the value of that attribute (instead of using & AMP ;) . If we cant use what is the purpose of specifying an attribute as CDATA in DTD? any help is appreciated
1
1590
by: ziycon | last post by:
Basically if there is a special character it will display fine on the page when you first go to the page but when you submit something new and the AJAX reloads the data on screen all special characters show up as unrecognised. Is there a way to handle special characters in AJAX properly, data is stored in a UTF-8 database??
1
9227
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9174
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6029
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4800
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3251
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2710
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.