Click to See Complete Forum and Search --> : Getting Values using Double quote
BRETTSTEVE
08-13-2004, 11:56 AM
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.
Charles
08-13-2004, 12:33 PM
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;">
steelersfan88
08-13-2004, 12:33 PM
Originally posted by BRETTSTEVE
if (!document.myform.old_value.value == document.myform.current .value)
{
}
else
{
alert("Save your changes");
}What happens when you add the red and remove the blue?
And yes, your quotes problem, look above ^
BRETTSTEVE
08-13-2004, 12:51 PM
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.
steelersfan88
08-13-2004, 12:58 PM
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
steelersfan88
08-13-2004, 12:59 PM
Originally posted by BRETTSTEVE
Replace " with &";
Thanks. See above. also, you should check the "Disable" smilies in this post checkbox, because that causes the ;) to become a smily.
BRETTSTEVE
08-13-2004, 01:10 PM
Thanks for your reply. Will try it out. Have fun supporting your team this NFL season.
BRETTSTEVE
08-13-2004, 01:34 PM
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?
Charles
08-13-2004, 01:38 PM
Please post the URL.
nitwit
08-13-2004, 01:53 PM
What programming are you using at the server? If it's PHP, for example, you can use htmlspecialchars (http://us3.php.net/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:
if (document.myform.current.value != document.myform.current.defaultValue)
alert("Save your changes");
}
BRETTSTEVE
08-13-2004, 01:54 PM
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
BRETTSTEVE
08-13-2004, 02:17 PM
It works. Thank you all.
Charles
08-13-2004, 02:18 PM
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>