|
|||||||
| JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...) |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Getting Values using Double quote
I have a form in which there is a text box. This text box shows values from the database and might contain single, double quotes. If the user changes some this value and clicks another link on the screen I have a javascript function which checks for the old value (from the database ) and the value that the user changes. If they are not the same I throw an alert prompting for changes.
I store the value from the database in a hidden input element and in the javascript function I check and see the following if (document.myform.old_value.value == document.myform.current .value) { } else { alert("Save your changes" } In this "old_value" is a hidden input element and "current" element is a text box. Without the quotes it works fine. But with the quotes it doens't work. I tried replacing the double quotes in the value that I get from the database with \" (which I store in the hidden element) but to no avail. Appreciate someone helping me. |
|
#2
|
||||
|
||||
|
If I understand you correctly, the problem is an HTML one; you're ending up with something like:
<input type="hidden" value="I thought I herd her say, "Good girls don't...""> The solution is to use something like: <input type="hidden" value="I thought I herd her say, &quot;Good girls don't...&quot;">
__________________
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” —Tim Berners-Lee, W3C Director and inventor of the World Wide Web |
|
#3
|
|||
|
|||
|
Re: Getting Values using Double quote
Quote:
And yes, your quotes problem, look above ^ |
|
#4
|
|||
|
|||
|
Hi Charles,
If I understand you right do you recommend me replacing the double quotes in the hidden HTML input element with an ampersand, followed by a double quote, followed by a semicolon. Is that right (Replace " with &" ![]() Thanks. |
|
#5
|
|||
|
|||
|
No, charles wants you to do and ampersand (&) followed by (quot) followed by a semicolon (;): &quot; will do it. Then also, don't forget to change the code and complete your alert with a closing parenthesis.
Dr. Script |
|
#6
|
|||
|
|||
|
Quote:
|
|
#7
|
|||
|
|||
|
Thanks for your reply. Will try it out. Have fun supporting your team this NFL season.
|
|
#8
|
|||
|
|||
|
Hi
It still doesn't work. In my web page for the hidden input element I have this (retrieved from the database and after that programatically I Replaced " with &"; <input type="hidden" value="I thought I herd her say, "Good girls don't...""> whereas in my textarea I have the following text (retrieved from the database). I thought I herd her say, "Good girls don't" In my javascript function I check for changes in this text.Though no changes have been made it still seems the old value and current value to be different. I go to view source and in the view source I still see &"; for the hidden input element. What is that I am doing wrong? |
|
#9
|
||||
|
||||
|
Please post the URL.
__________________
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” —Tim Berners-Lee, W3C Director and inventor of the World Wide Web |
|
#10
|
|||
|
|||
|
What programming are you using at the server? If it's PHP, for example, you can use htmlspecialchars to 'sanitize' outgoing code.
In any event, you don't need that hidden field: all HTML form controls have DOM properties that store the original values (set in the HTML). So: Code:
if (document.myform.current.value != document.myform.current.defaultValue)
alert("Save your changes");
}
|
|
#11
|
|||
|
|||
|
Thanks Charles.
This is what I see when I say view source. <input name="old_value" type="hidden" value = "Thi&";s i&";s just a T&";Est" > <td colspan="2" align="left"> This is what it is for the text area. Exact values from the Database <td colspan="4"> <textarea NAME="current_value" COLS="60" ROWS="5">Thi"s i"s just a T"Est</textarea></td> Also this is my javascript function if (document.myform.old_value.value == document.myform.current .value) { } else { alert("Save your changes") } Even now if I dont make any chanes it still alerts me |
|
#12
|
|||
|
|||
|
thanks everybody
It works. Thank you all.
|
|
#13
|
||||
|
||||
|
I had a wee boo-boo. It seems that browsers aren't resolving the mnemonic character entity. You'll have to use the character number (34).
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Content-Script-Type" content="text/javascript"> <meta name="Content-Style-Type" content="text/css"> <title>Example</title> </head> <body> <form action="someScript.pl" onsubmit="alert(this.hidden.value == this.area.value); return false"> <fieldset> <legend>Example</legend> <input id="hidden" type="hidden" value="Thi&#34;s i&#34;s just a T&#34;Est"> <textarea id="area">Thi"s i"s just a T"Est</textarea> <button type="Submit">Submit</button> </fieldset> </form> </body> </html>
__________________
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.” —Tim Berners-Lee, W3C Director and inventor of the World Wide Web |
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|