www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 08-13-2004, 11:56 AM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    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.
    Reply With Quote
      #2  
    Old 08-13-2004, 12:33 PM
    Charles's Avatar
    Charles Charles is offline
    JavaScript Banned
     
    Join Date: Nov 2002
    Location: Baltimore, Maryland
    Posts: 11,667
    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, &amp;quot;Good girls don't...&amp;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
    Reply With Quote
      #3  
    Old 08-13-2004, 12:33 PM
    steelersfan88 steelersfan88 is offline
    Banned
     
    Join Date: Jun 2003
    Location: The United States Site: http://kellyj.t35.com
    Posts: 2,718
    Re: Getting Values using Double quote

    Quote:
    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 ^
    Reply With Quote
      #4  
    Old 08-13-2004, 12:51 PM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    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.
    Reply With Quote
      #5  
    Old 08-13-2004, 12:58 PM
    steelersfan88 steelersfan88 is offline
    Banned
     
    Join Date: Jun 2003
    Location: The United States Site: http://kellyj.t35.com
    Posts: 2,718
    No, charles wants you to do and ampersand (&) followed by (quot) followed by a semicolon (;): &amp;quot; will do it. Then also, don't forget to change the code and complete your alert with a closing parenthesis.

    Dr. Script
    Reply With Quote
      #6  
    Old 08-13-2004, 12:59 PM
    steelersfan88 steelersfan88 is offline
    Banned
     
    Join Date: Jun 2003
    Location: The United States Site: http://kellyj.t35.com
    Posts: 2,718
    Quote:
    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.
    Reply With Quote
      #7  
    Old 08-13-2004, 01:10 PM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    Thanks for your reply. Will try it out. Have fun supporting your team this NFL season.
    Reply With Quote
      #8  
    Old 08-13-2004, 01:34 PM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    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, &quot;Good girls don't...&quot;">

    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?
    Reply With Quote
      #9  
    Old 08-13-2004, 01:38 PM
    Charles's Avatar
    Charles Charles is offline
    JavaScript Banned
     
    Join Date: Nov 2002
    Location: Baltimore, Maryland
    Posts: 11,667
    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
    Reply With Quote
      #10  
    Old 08-13-2004, 01:53 PM
    nitwit nitwit is offline
    Registered User
     
    Join Date: Aug 2004
    Location: Zimbabwe
    Posts: 68
    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");
    }
    Reply With Quote
      #11  
    Old 08-13-2004, 01:54 PM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    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
    Reply With Quote
      #12  
    Old 08-13-2004, 02:17 PM
    BRETTSTEVE BRETTSTEVE is offline
    Registered User
     
    Join Date: Aug 2004
    Posts: 6
    thanks everybody

    It works. Thank you all.
    Reply With Quote
      #13  
    Old 08-13-2004, 02:18 PM
    Charles's Avatar
    Charles Charles is offline
    JavaScript Banned
     
    Join Date: Nov 2002
    Location: Baltimore, Maryland
    Posts: 11,667
    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&amp;#34;s i&amp;#34;s just a T&amp;#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
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    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

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 10:42 AM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.